Hands-On Machine Learning with Scikit-Learn and TensorFlow


| Chapter 4: Training Models



Download 26,57 Mb.
Pdf ko'rish
bet110/225
Sana16.03.2022
Hajmi26,57 Mb.
#497859
1   ...   106   107   108   109   110   111   112   113   ...   225
Bog'liq
Hands on Machine Learning with Scikit Learn Keras and TensorFlow

132 | Chapter 4: Training Models


Clearly, a straight line will never fit this data properly. So let’s use Scikit-Learn’s 
Poly
nomialFeatures
class to transform our training data, adding the square (2
nd
-degree
polynomial) of each feature in the training set as new features (in this case there is
just one feature):
>>> 
from
sklearn.preprocessing
import
PolynomialFeatures
>>> 
poly_features
=
PolynomialFeatures
(
degree
=
2

include_bias
=
False
)
>>> 
X_poly
=
poly_features
.
fit_transform
(
X
)
>>> 
X
[
0
]
array([-0.75275929])
>>> 
X_poly
[
0
]
array([-0.75275929, 0.56664654])
X_poly
now contains the original feature of 
X
plus the square of this feature. Now you
can fit a 
LinearRegression
model to this extended training data (
Figure 4-13
):
>>> 
lin_reg
=
LinearRegression
()
>>> 
lin_reg
.
fit
(
X_poly

y
)
>>> 
lin_reg
.
intercept_

lin_reg
.
coef_
(array([1.78134581]), array([[0.93366893, 0.56456263]]))
Figure 4-13. Polynomial Regression model predictions
Not bad: the model estimates 
y
= 0 . 56
x
1
2
+ 0 . 93
x
1
+ 1 . 78 when in fact the original
function was 
y
= 0 . 5
x
1
2
+ 1 . 0
x
1
+ 2 . 0 + Gaussian noise.
Note that when there are multiple features, Polynomial Regression is capable of find‐
ing relationships between features (which is something a plain Linear Regression
model cannot do). This is made possible by the fact that 
PolynomialFeatures
also
adds all combinations of features up to the given degree. For example, if there were

Download 26,57 Mb.

Do'stlaringiz bilan baham:
1   ...   106   107   108   109   110   111   112   113   ...   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