错误为"plot_decision_regions"的错误“当X具有两个以上的训练特征时,必须提供填充值". [英] plot_decision_regions with error "Filler values must be provided when X has more than 2 training features."

查看:1082
本文介绍了错误为"plot_decision_regions"的错误“当X具有两个以上的训练特征时,必须提供填充值".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为SVC Bernoulli输出绘制2D图.

I am plotting 2D plot for SVC Bernoulli output.

从平均word2vec和标准数据转换为向量 拆分数据进行训练和测试. 通过网格搜索找到了最好的C和gamma(rbf)

converted to vectors from Avg word2vec and standerdised data split data to train and test. Through grid search found the best C and 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数组.找到

Receive error :- ValueError: y must be a NumPy array. Found

还尝试将y转换为numpy.然后提示错误 ValueError:y必须为整数数组.找到的对象.尝试将数组作为y.astype(np.integer)传递

also tried to convert the y to numpy. Then it prompts error ValueError: y must be an integer array. Found object. Try passing the array as y.astype(np.integer)

最后我将其转换为整数数组. 现在它提示错误. ValueError:X具有两个以上的训练功能时,必须提供填充值.

finally i converted it to integer array. Now it is prompting of error. ValueError: Filler values must be provided when X has more than 2 training features.

推荐答案

您可以使用PCA将数据多维数据缩减为二维数据.然后将获得的结果传递到plot_decision_region中,将不需要填充值.

You can use PCA to reduce your data multi-dimensional data to two dimensional data. Then pass the obtained result in plot_decision_region and there will be no need of filler values.

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)

这篇关于错误为"plot_decision_regions"的错误“当X具有两个以上的训练特征时,必须提供填充值".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆