線形モデルの決定境界線の式を得るには、coef_
とintercept_
の両方を取得する必要があります。また、SVCを使用しているので、複数の決定境界が存在することにも注意してください。ライン式のように構築することができ
:
w0
が
intercept_
から得られる
y = w0 + w1 * x1 + w2 * x2 + ...
、w1
以降coef_
で発見され、以降x1
とは、あなたの機能です。
たとえば、このコードでは、各決定境界の式を印刷する方法を示します。この例では
from sklearn import svm
import numpy as np
clf = svm.SVC(kernel="linear")
X = np.array([[1, 2], [3, 4], [5, 1], [6, 2]])
y = np.array(["A", "B", "A", "C"])
clf.fit(X, y)
for (intercept, coef) in zip(clf.intercept_, clf.coef_):
s = "y = {0:.3f}".format(intercept)
for (i, c) in enumerate(coef):
s += " + {0:.3f} * x{1}".format(c, i)
print(s)
、ラインがあると判定された:
y = 2.800 + -0.200 * x0 + -0.800 * x1
y = 7.000 + -1.000 * x0 + -1.000 * x1
y = 1.154 + -0.462 * x0 + 0.308 * x1
出典:http://scikit-learn.org/stable/modules/linear_model.html