Skip to Content
精通機器學習
book

精通機器學習

by Aurélien Géron
April 2020
Intermediate to advanced
816 pages
18h 32m
Chinese
GoTop Information, Inc.
Content preview from 精通機器學習
86
|
第三章:分類
訓練二元分類器
我們先簡化問題
只嘗試辨識一個數字
例如
數字
5
這個
數字
5
偵測器
是個
二元
分類器
它只能分辨兩個類別
5
和非
5
我們為這項分類任務建立目標向量
y_train_5 = (y_train == 5) #
所有的
5
都是
True
所有其他數字都是
False
y_test_5 = (y_test == 5)
我們接著選擇一種分類器並訓練它
隨機梯度下降
Stochastic Gradient DescentSGD
分類器是很好的起點
Scikit-Learn
SGDClassifier
類別
這個分類器的優點是
它可
以高效地處理非常大型的資料組
部分的原因是
SGD
以獨立的方式處理訓練實例
每次
處理一個
所以
SGD
非常適合用在線上學習
)。
我們來建立一個
SGDClassifier
並且用
整個訓練組訓練它
from sklearn.linear_model import
SGDClassifier
sgd_clf = SGDClassifier(random_state=42)
sgd_clf.fit(X_train, y_train_5)
SGDClassifier
的訓練過程需要依靠隨機性
因此名字中有
隨機
stochastic)」)。
如果你想要重現結果
就要設定
random_state
參數
我們用它來偵測數字
5
的圖片
>>>
sgd_clf.predict([some_digit])
array([ True])
分類器猜測這張圖片代表
5
True
)。
看起來它在這個案例猜對了 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

下一代空间计算:AR与VR创新理论与实践

下一代空间计算:AR与VR创新理论与实践

Erin Pangilinan, Steve Lukas, Vasanth Mohan
C语言核心技术(原书第2版)

C语言核心技术(原书第2版)

Peter Prinz, Tony Crawford

Publisher Resources

ISBN: 9789865024345