Hands-On Machine Learning with Scikit-Learn and TensorFlow


Regularized Linear Models | 139



Download 26,57 Mb.
Pdf ko'rish
bet116/225
Sana16.03.2022
Hajmi26,57 Mb.
#497859
1   ...   112   113   114   115   116   117   118   119   ...   225
Bog'liq
Hands on Machine Learning with Scikit Learn Keras and TensorFlow

Regularized Linear Models | 139


14
Alternatively you can use the 
Ridge
class with the 
"sag"
solver. Stochastic Average GD is a variant of SGD.
For more details, see the presentation 
“Minimizing Finite Sums with the Stochastic Average Gradient Algo‐
rithm”
by Mark Schmidt et al. from the University of British Columbia.
Figure 4-17. Ridge Regression
Equation 4-9. Ridge Regression closed-form solution
θ X
T
+
α
A
−1
X
T
y
Here is how to perform Ridge Regression with Scikit-Learn using a closed-form solu‐
tion (a variant of 
Equation 4-9
using a matrix factorization technique by André-Louis
Cholesky):
>>> 
from
sklearn.linear_model
import
Ridge
>>> 
ridge_reg
=
Ridge
(
alpha
=
1

solver
=
"cholesky"
)
>>> 
ridge_reg
.
fit
(
X

y
)
>>> 
ridge_reg
.
predict
([[
1.5
]])
array([[1.55071465]])
And using Stochastic Gradient Descent:
14
>>> 
sgd_reg
=
SGDRegressor
(
penalty
=
"l2"
)
>>> 
sgd_reg
.
fit
(
X

y
.
ravel
())
>>> 
sgd_reg
.
predict
([[
1.5
]])
array([1.47012588])
The 
penalty
hyperparameter sets the type of regularization term to use. Specifying
"l2"
indicates that you want SGD to add a regularization term to the cost function 
equal to half the square of the ℓ
2
norm of the weight vector: this is simply Ridge
Regression.

Download 26,57 Mb.

Do'stlaringiz bilan baham:
1   ...   112   113   114   115   116   117   118   119   ...   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