Hands-On Machine Learning with Scikit-Learn and TensorFlow


| Chapter 5: Support Vector Machines



Download 26,57 Mb.
Pdf ko'rish
bet132/225
Sana16.03.2022
Hajmi26,57 Mb.
#497859
1   ...   128   129   130   131   132   133   134   135   ...   225
Bog'liq
Hands on Machine Learning with Scikit Learn Keras and TensorFlow

160 | Chapter 5: Support Vector Machines


Nonlinear SVM Classification
Although linear SVM classifiers are efficient and work surprisingly well in many
cases, many datasets are not even close to being linearly separable. One approach to
handling nonlinear datasets is to add more features, such as polynomial features (as
you did in 
Chapter 4
); in some cases this can result in a linearly separable dataset.
Consider the left plot in 
Figure 5-5
: it represents a simple dataset with just one feature
x
1
. This dataset is not linearly separable, as you can see. But if you add a second fea‐
ture 
x
2
= (
x
1
)
2
, the resulting 2D dataset is perfectly linearly separable.
Figure 5-5. Adding features to make a dataset linearly separable
To implement this idea using Scikit-Learn, you can create a 
Pipeline
containing a
PolynomialFeatures
 transformer (discussed in 
“Polynomial Regression” on page
132
), followed by a 
StandardScaler
and a 
LinearSVC
. Let’s test this on the moons
dataset: this is a toy dataset for binary classification in which the data points are sha‐
ped as two interleaving half circles (see 
Figure 5-6
). You can generate this dataset
using the 
make_moons()
function:
from
sklearn.datasets
import
make_moons
from
sklearn.pipeline
import
Pipeline
from
sklearn.preprocessing
import
PolynomialFeatures
polynomial_svm_clf
=
Pipeline
([
(
"poly_features"

PolynomialFeatures
(
degree
=
3
)),
(
"scaler"

StandardScaler
()),
(
"svm_clf"

LinearSVC
(
C
=
10

loss
=
"hinge"
))
])
polynomial_svm_clf
.
fit
(
X

y
)

Download 26,57 Mb.

Do'stlaringiz bilan baham:
1   ...   128   129   130   131   132   133   134   135   ...   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