Hands-On Machine Learning with Scikit-Learn and TensorFlow



Download 26,57 Mb.
Pdf ko'rish
bet52/225
Sana16.03.2022
Hajmi26,57 Mb.
#497859
1   ...   48   49   50   51   52   53   54   55   ...   225
Bog'liq
Hands on Machine Learning with Scikit Learn Keras and TensorFlow

from
sklearn.impute
import
SimpleImputer
imputer
=
SimpleImputer
(
strategy
=
"median"
)
Since the median can only be computed on numerical attributes, we need to create a
copy of the data without the text attribute 
ocean_proximity
:
housing_num
=
housing
.
drop
(
"ocean_proximity"

axis
=
1
)
Now you can fit the 
imputer
instance to the training data using the 
fit()
method:
imputer
.
fit
(
housing_num
)
The 
imputer
has simply computed the median of each attribute and stored the result
in its 
statistics_
instance variable. Only the 
total_bedrooms
attribute had missing
values, but we cannot be sure that there won’t be any missing values in new data after
the system goes live, so it is safer to apply the 
imputer
to all the numerical attributes:
>>> 
imputer
.
statistics_
array([ -118.51 , 34.26 , 29. , 2119.5 , 433. , 1164. , 408. , 3.5409])
Prepare the Data for Machine Learning Algorithms | 69


16
For more details on the design principles, see “API design for machine learning software: experiences from
the scikit-learn project,” L. Buitinck, G. Louppe, M. Blondel, F. Pedregosa, A. Müller, et al. (2013).
>>> 
housing_num
.
median
()
.
values
array([ -118.51 , 34.26 , 29. , 2119.5 , 433. , 1164. , 408. , 3.5409])
Now you can use this “trained” 
imputer
to transform the training set by replacing
missing values by the learned medians:
X
=
imputer
.
transform
(
housing_num
)
The result is a plain NumPy array containing the transformed features. If you want to
put it back into a Pandas DataFrame, it’s simple:
housing_tr
=
pd
.
DataFrame
(
X

columns
=
housing_num
.
columns
)

Download 26,57 Mb.

Do'stlaringiz bilan baham:
1   ...   48   49   50   51   52   53   54   55   ...   225




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish