【问题标题】:Finding the accuracy - Found array with dim 3. Estimator expected <= 2找到准确度 - 找到暗淡 3 的数组。估计器预期 <= 2
【发布时间】:2018-07-13 14:19:39
【问题描述】:

我有以下 Python 代码 sn-p,我试图在某些数据上运行 SVC(使用的库是 scikit-learn:

(trainFeat, testFeat, trainLabels, testLabels) = train_test_split(
    data, data_labels, test_size=0.20, random_state=42)

model = SVC(kernel='poly', max_iter=10,probability=True,class_weight='balanced')
model.fit(np.reshape(trainFeat, (124,-1)), trainLabels)
accuracy = model.score(testFeat, testLabels)
print('Accuracy: {:.2f}%'.format(acc * 100))

但是,accuracy = model.score(testFeat, testLabels) 出现以下错误:

ValueError: Found array with dim 3. Estimator expected <= 2.

我应该怎么做才能修复这个错误?

谢谢。

【问题讨论】:

标签: python arrays numpy model scikit-learn


【解决方案1】:

当我在另一个问题here 中应用 cᴏʟᴅsᴘᴇᴇᴅ 的建议时,代码有效:

model.score(np.reshape(testFeat, (-1, 9 * 6)), testLabels)

【讨论】:

    【解决方案2】:

    我猜,您预测的是 3 个班级。它为您提供了每个类概率的 3 维数组。

    尝试这样做:

    model = SVC(kernel='poly', max_iter=10,probability=False,class_weight='balanced')
    

    【讨论】:

    • 我实际上是在尝试预测 2 个类别。我尝试了您的建议,但错误仍然存​​在
    猜你喜欢
    • 2019-06-01
    • 2018-01-16
    • 2016-04-24
    • 2016-11-28
    • 2021-04-16
    • 2019-07-19
    • 2018-06-08
    • 2021-05-10
    • 1970-01-01
    相关资源
    最近更新 更多