B*jperimewt-1
Dmonslrate the folowing Dala jorgmot
ng 9ylhom Libravies
fasko usi
Loadimg the dotaset
9 the deseudeut and
9Tdeuliying
indyoendout vaviables.
missimg
witli data
jDealing as od
Iu: iwpo! oandas
Tm;ijport umjoy as ne
d.vead- exel (r'c:lusers\Pe-es\
dola Documents\dataset.alsa)
data
age Salay
25.0 21000.O
2 25.0 21000.o
3 21-0 18000. O
3 33.0 45o00.o
5 38.0 50000. o
L45.0 63000.0
56.0 Nan
Nan 21000.0
53.0 4l000.O
55000. D
Tu: xdata. ilo , :-1
X
Oud: age
25.0
2 25.0
2 3 20
33.O
3
5 38.0
4
y5.0
56.0
53.D
8
40.0
y:data.iloc [:,-],alues
Tu:
ISoo0., 5ao
500., 50000.,
21000,
Outiarvay([21000., 55 o00.)
7lo00.,
6300 ) Man, 2loo0,,
21000,)
sklean.impute imjoort Simole -
Tuifroa -Tuouta
Dalues=tpna4
strateay:"umean)
x- iwje. fit transfom (2)
Y-y. reshaye Ci,)
4:ijo. fit.thausfovnaly)
Iy.resliajoe (-1)
out: array (tti:, 25.],
{l2., 25],
[3. 21],
[4.33],
[5. 38-],
I6. 45],
[.56.],
l8.2734.3333
[9.53],
Ho J])
Tu:
(E210oo., 2l000, l8000., 45000)
out: avay 40555. 55ss6
FBoe,) 2/oO0)
Foo00, 63o00
7l000. 5S000])
aditya lo 9
fail
32 20
fail kySr 8
28 nagati
Jpa5s
64
24 aditya
fasl G 5
31
22 pragati
joass 4
q9 23
4 3
20
23 Joass 3 2
fail adityaGko
33 2
Jorogai
19 ollge Gvo Out -o
marks vesul!
ota) dataset
-al pd.dalaset
isjpovt
Sels.
d
anthaining imto dolasel
Jeatuves the Scalg
Daling a)
calegovical
dala
with
ibvarieS, ython using tasks
datafollozoing the bate Dosons
Iu: Z: dataseB. iloc [:.[o. 2, 3)).
ales
y: datast. iloc /:.1), Dalue 5
from shlean.jr0te6ing iwjort
CabclEmcocdey, Ome Jlol Encoder
le-x: labelE ucodal)
x[:.0). le_x.fit_trasfom (zl:,o)
Ohe_arOuetotEmodr(ategorical-jeaaes
z: lo1)
olhe.fidtran sform(e).to os ay)
Cut avray ([lo., 1., 1, .. 1,1. oJ
1. 0.) O.) . , 1-1., OJ,
l1., O, O., . , 1., 1-, 0.J,
Dyo., ., . y 1., l., o],
ST:fon skleoru.model_ Gelecion iuqporl
train-testSjolit
Arain,ztety tain, y_test :
rain_test Slifzy, test. Si~e zO.25,
van do_state : o)
array (ll t,
Out : ar
i,O., o., ..., , l., o.
f, .,0., ..., 1., 1., 0.1)
Tu; xtest
Oul ay ([[l,O., O.,
[., o. ,o., ,o
l.,O.,0., .. , 0.]
(.,o.,o., I., ..., O.,
O., l.,',-.. o.]])
anay (T' rgati, 'adiyo. 'ngabi, S1ki,
gh' Srkei. Grka's'rgati, adityd l,dye
o5jet)
6 T:fom Shlearn. jorcpross ing ijport
Stadavdscal
S-x-Sa nlovdSalo()
2.lest : Gcz.tausfom (-test)
SC-y: slarlavdScaler ()
Jlvain : ytvain. veshaps ((lerly.tyai) ))
y. tvam
=Sc-y.Jl. hausform(3. trai)
y. train.valelc)
outs arvay ([lo.y08 24; -o.lj03,... O. 4o8229,
0.408 9, - oy0824]
Lo.4og24,-0.4o8,:.. o. Yo224,
-O.40824)
O 4o82 4,
lo. 40824 229, -0,Ho824,-)
O.HoB 24, -0.yo24 J)
Tu:. ztest
out: aray ([t l.co00
O0G O0, -s876-l4 1)
ceniqur
)) (it. (ty) xlabl plt
)) (up.tuniquec*),
1djoy uyo. jolt-plot
(ay) scattor jolt.
Js2.Vandom
and #plolxvaudu(s) 25,an
dom.
(is)vandu data prepave #
Seed42) do. no.a1
atoy umber taport
as matplotib.
seed jolt# Pyplot
twport Sciy. jrom stats
nd kuasou
p as
where
`(a,- (ay. coRR a]
(-9) a)
Manhatt
aw e|
e]
di6lauco
distame
simnilariy ]Taccavd
Siwilarity blpcoSi
ue
latiou Covwe dissimilavity
ytusig wethods
follouwig Deoushate
the
Baercise
-3
2/2/
6 cosine Sinilarity :
S(«y):
aivoise import Cos
melrics
fron sklean. Simia
CoS Similarity (oc. veshagell,-47:s
Gim:Cosive
Jot(osie Similarity: %.3f %cos_ Sim)
Jákkavd Siuilarity:
Ta,B). lan8)
lAUB]
Gnplementaton
from skleam, metbrics iajport jacand Scove
4: [ , 1, o)
B= (2,2, O,1)
jau jaciard siove (A,B)
bint ('Tauavd Siilarity: o. sf '%jaiy
Euc(xy :/} («;-y)
jovograwM
Siey.Sjotial imjaort distane
dst = distane. eueli deau (ry)
jorint('uclidean distance : %3f %dst)
e MaubhaHam asta Mie -
Manlattan
|Tmplementation ythou
Spdial import distawe
Joa Gciy.
dst distauce, cityblok(ay)
dstauce: %3f' %dst)
Jbrint("Mauhattan
nanhotton distan ei lo.Y68