1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Python】scikit-learnのサポートベクタマシンでのデータの分類

Posted at

サポートベクタマシンでデータを直線で分類する場合は、引数を「kernel='linear'」とします。

from sklearn.svm import SVC
model = SVC(kernel='linear')
model.fit(X, y)

image.png

直線で分類できない場合は、引数を「kernel='rbf'」として曲線で分類します。

model = SVC(kernel='rbf')
model.fit(X, y)
image.png

rbfは「radial basis function」の略で、日本語にすると放射基底関数です。サポートベクタマシンはデフォルトで「kernel='rbf'」となっているため、引数を付けなければ直線にも曲線にも対応できます。

polyは多項式カーネルで、デフォルトは3次多項式で分類します。引数の「degree」で次数を上げると精度が良くなることがありますが、rbfのほうが良い結果になることが多いです。

引数「C」はマージンの広さを設定するものです。値が大きいとマージンは狭くなり、値が小さいとマージンは広くなります。

【C=10】

model = SVC(kernel='linear')
model.fit(X, y)

image.png

【C=0.1】

model = SVC(kernel='linear')
model.fit(X, y)

image.png

モデルに柔軟性を持たせる場合はCの値を小さくして、厳密にする場合はCの値を大きくします。ただし、柔軟性があると誤判定が増え、厳密にすると訓練データに過剰適合します。グリッドサーチを利用すると最適なパラメータを求めることができます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?