gpt4 book ai didi

python - 绘制分类器的决策边界,ValueError : X has 2 features per sample; expecting 908430"

转载 作者:行者123 更新时间:2023-11-30 09:53:30 25 4
gpt4 key购买 nike

基于 scikit-learn 文档 http://scikit-learn.org/stable/auto_examples/svm/plot_iris.html#sphx-glr-auto-examples-svm-plot-iris-py 。我尝试绘制分类器的决策边界,但它发送一条错误消息,调用“ValueError:X 每个样本有 2 个特征;期望 908430”,此代码“Z = clf.predict(np.c_[xx.ravel()” , yy.ravel()])"

clf = SGDClassifier().fit(step2, index)  
X=step2
y=index
h = .02
colors = "bry"
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(y_min, y_max, h))

Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])

# Put the result into a color plot
Z = Z.reshape(xx.shape)
plt.contourf(xx, yy, Z, cmap=plt.cm.Paired)
plt.axis('off')

# Plot also the training points
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Paired)

“索引”是一个标签,其中包含大约 [98579 X 1] 的评论标签,其中包括正面、自然和负面

array(['N', 'N', 'P', ..., 'NEU', 'P', 'N'], dtype=object)

“step2”是由 Countvectorizer 函数形成的 [98579 X 908430] numpy 矩阵,它是关于评论数据的

<98579x908430 sparse matrix of type '<type 'numpy.float64'>'
with 3168845 stored elements in Compressed Sparse Row format>

最佳答案

问题是您无法为非二维数据的分类器绘制决策边界。您的数据显然是高维的,它有 908430 个维度(我假设是 NLP 任务)。无法为此类模型绘制实际决策边界。您使用的示例是在二维数据(减少虹膜)上进行训练的,这是他们能够绘制它的唯一原因

关于python - 绘制分类器的决策边界,ValueError : X has 2 features per sample; expecting 908430",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40103060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com