相关疑难解决方法(0)

绘制超平面线性SVM Python

我正在尝试为用LinearSVC和sklearn训练的模型绘制超平面。请注意,我正在使用自然语言。在拟合模型之前,我使用CountVectorizer和TfidfTransformer提取了特征。

这里是分类器:

from sklearn.svm import LinearSVC
from sklearn import svm

clf = LinearSVC(C=0.2).fit(X_train_tf, y_train)
Run Code Online (Sandbox Code Playgroud)

然后我尝试按照Scikit-learn网站上的建议进行绘图:

# get the separating hyperplane
w = clf.coef_[0]
a = -w[0] / w[1]
xx = np.linspace(-5, 5)
yy = a * xx - (clf.intercept_[0]) / w[1]

# plot the parallels to the separating hyperplane that pass through the
# support vectors
b = clf.support_vectors_[0]
yy_down = a * xx + (b[1] - a * b[0])
b = clf.support_vectors_[-1]
yy_up = a * xx …
Run Code Online (Sandbox Code Playgroud)

python matplotlib svm scikit-learn

2
推荐指数
1
解决办法
6738
查看次数

标签 统计

matplotlib ×1

python ×1

scikit-learn ×1

svm ×1