Hands-On Machine Learning with Scikit-Learn and TensorFlow


| Chapter 2: End-to-End Machine Learning Project



Download 26,57 Mb.
Pdf ko'rish
bet66/225
Sana16.03.2022
Hajmi26,57 Mb.
#497859
1   ...   62   63   64   65   66   67   68   69   ...   225
Bog'liq
Hands on Machine Learning with Scikit Learn Keras and TensorFlow

80 | Chapter 2: End-to-End Machine Learning Project


You should save every model you experiment with, so you can
come back easily to any model you want. Make sure you save both
the hyperparameters and the trained parameters, as well as the
cross-validation scores and perhaps the actual predictions as well.
This will allow you to easily compare scores across model types,
and compare the types of errors they make. You can easily save
Scikit-Learn models by using Python’s 
pickle
module, or using
sklearn.externals.joblib
, which is more efficient at serializing 
large NumPy arrays:
from
sklearn.externals
import
joblib
joblib
.
dump
(
my_model

"my_model.pkl"
)
# and later...
my_model_loaded
=
joblib
.
load
(
"my_model.pkl"
)
Fine-Tune Your Model
Let’s assume that you now have a shortlist of promising models. You now need to
fine-tune them. Let’s look at a few ways you can do that.
Grid Search
One way to do that would be to fiddle with the hyperparameters manually, until you
find a great combination of hyperparameter values. This would be very tedious work,
and you may not have time to explore many combinations.
Instead you should get Scikit-Learn’s 
GridSearchCV
to search for you. All you need to
do is tell it which hyperparameters you want it to experiment with, and what values to
try out, and it will evaluate all the possible combinations of hyperparameter values,
using cross-validation. For example, the following code searches for the best combi‐
nation of hyperparameter values for the 
RandomForestRegressor
:
from
sklearn.model_selection
import
GridSearchCV
param_grid
=
[
{
'n_estimators'
: [
3

10

30
], 
'max_features'
: [
2

4

6

8
]},
{
'bootstrap'
: [
False
], 
'n_estimators'
: [
3

10
], 
'max_features'
: [
2

3

4
]},
]
forest_reg
=
RandomForestRegressor
()
grid_search
=
GridSearchCV
(
forest_reg

param_grid

cv
=
5
,
scoring
=
'neg_mean_squared_error'
,
return_train_score
=
True
)
grid_search
.
fit
(
housing_prepared

housing_labels
)

Download 26,57 Mb.

Do'stlaringiz bilan baham:
1   ...   62   63   64   65   66   67   68   69   ...   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