Hands-On Machine Learning with Scikit-Learn and TensorFlow



Download 26,57 Mb.
Pdf ko'rish
bet89/225
Sana16.03.2022
Hajmi26,57 Mb.
#497859
1   ...   85   86   87   88   89   90   91   92   ...   225
Bog'liq
Hands on Machine Learning with Scikit Learn Keras and TensorFlow

>>> 
from
sklearn.multiclass
import
OneVsOneClassifier
>>> 
ovo_clf
=
OneVsOneClassifier
(
SGDClassifier
(
random_state
=
42
))
>>> 
ovo_clf
.
fit
(
X_train

y_train
)
>>> 
ovo_clf
.
predict
([
some_digit
])
Multiclass Classification | 105


array([5], dtype=uint8)
>>> 
len
(
ovo_clf
.
estimators_
)
45
Training a 
RandomForestClassifier
is just as easy:
>>> 
forest_clf
.
fit
(
X_train

y_train
)
>>> 
forest_clf
.
predict
([
some_digit
])
array([5], dtype=uint8)
This time Scikit-Learn did not have to run OvA or OvO because Random Forest
classifiers can directly classify instances into multiple classes. You can call
predict_proba()
to get the list of probabilities that the classifier assigned to each
instance for each class:
>>> 
forest_clf
.
predict_proba
([
some_digit
])
array([[0. , 0. , 0.01, 0.08, 0. , 0.9 , 0. , 0. , 0. , 0.01]])
You can see that the classifier is fairly confident about its prediction: the 0.9 at the 5
th
index in the array means that the model estimates a 90% probability that the image
represents a 5. It also thinks that the image could instead be a 2, a 3 or a 9, respec‐
tively with 1%, 8% and 1% probability.
Now of course you want to evaluate these classifiers. As usual, you want to use cross-
validation. Let’s evaluate the 
SGDClassifier
’s accuracy using the 
cross_val_score()
function:
>>> 
cross_val_score
(
sgd_clf

X_train

y_train

cv
=
3

scoring
=
"accuracy"
)
array([0.8489802 , 0.87129356, 0.86988048])
It gets over 84% on all test folds. If you used a random classifier, you would get 10%
accuracy, so this is not such a bad score, but you can still do much better. For exam‐
ple, simply scaling the inputs (as discussed in 
Chapter 2
) increases accuracy above
89%:

Download 26,57 Mb.

Do'stlaringiz bilan baham:
1   ...   85   86   87   88   89   90   91   92   ...   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