我正在绘制 SVC 伯努利输出的 2D 图。
从 Avg word2vec 和标准化数据转换为向量
分割数据进行训练和测试。
通过网格搜索找到最好的C和gamma(rbf)
clf = SVC(C=100,gamma=0.0001)
clf.fit(X_train1,y_train)
from mlxtend.plotting import plot_decision_regions
plot_decision_regions(X_train, y_train, clf=clf, legend=2)
plt.xlabel(X.columns[0], size=14)
plt.ylabel(X.columns[1], size=14)
plt.title('SVM Decision Region Boundary', size=16)
接收错误:-
ValueError:y 必须是 NumPy 数组。成立
还尝试将 y 转换为 numpy。然后就提示错误
ValueError:y 必须是整数数组。找到对象了。尝试将数组作为 y.astype(np.integer) 传递
最后我将它转换为整数数组。
现在提示错误。
ValueError:当 X 具有超过 2 个训练特征时,必须提供填充值。
您可以使用PCA将您的数据多维数据减少为二维数据。然后将得到的结果传入plot_decision_region
并且不需要填充值。
from sklearn.decomposition import PCA
from mlxtend.plotting import plot_decision_regions
clf = SVC(C=100,gamma=0.0001)
pca = PCA(n_components = 2)
X_train2 = pca.fit_transform(X_train)
clf.fit(X_train2, y_train)
plot_decision_regions(X_train2, y_train, clf=clf, legend=2)
plt.xlabel(X.columns[0], size=14)
plt.ylabel(X.columns[1], size=14)
plt.title('SVM Decision Region Boundary', size=16)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)