Hands-On Machine Learning with Scikit-Learn and TensorFlow



Download 26,57 Mb.
Pdf ko'rish
bet57/225
Sana16.03.2022
Hajmi26,57 Mb.
#497859
1   ...   53   54   55   56   57   58   59   60   ...   225
Bog'liq
Hands on Machine Learning with Scikit Learn Keras and TensorFlow

Custom Transformers
Although Scikit-Learn provides many useful transformers, you will need to write
your own for tasks such as custom cleanup operations or combining specific
attributes. You will want your transformer to work seamlessly with Scikit-Learn func‐
tionalities (such as pipelines), and since Scikit-Learn relies on duck typing (not inher‐
itance), all you need is to create a class and implement three methods: 
fit()
(returning 
self
), 
transform()
, and 
fit_transform()
. You can get the last one for
free by simply adding 
TransformerMixin
as a base class. Also, if you add 
BaseEstima
tor
as a base class (and avoid 
*args
and 
**kargs
in your constructor) you will get
two extra methods (
get_params()
and 
set_params()
) that will be useful for auto‐
Prepare the Data for Machine Learning Algorithms | 73


matic hyperparameter tuning. For example, here is a small transformer class that adds
the combined attributes we discussed earlier:
from
sklearn.base
import
BaseEstimator

TransformerMixin
rooms_ix

bedrooms_ix

population_ix

households_ix
=
3

4

5

6
class
CombinedAttributesAdder
(
BaseEstimator

TransformerMixin
):
def
__init__
(
self

add_bedrooms_per_room
=
True
): 
# no *args or **kargs
self
.
add_bedrooms_per_room
=
add_bedrooms_per_room
def
fit
(
self

X

y
=
None
):

Download 26,57 Mb.

Do'stlaringiz bilan baham:
1   ...   53   54   55   56   57   58   59   60   ...   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