【问题标题】:Scikit-learn ValueError: unknown is not supported when using confusion matrixScikit-learn ValueError:使用混淆矩阵时不支持未知
【发布时间】:2018-01-15 00:55:46
【问题描述】:

我正在使用混淆矩阵模块将类预测结果与实际值进行比较。

val= ... #shape (3000,1,30) dtype float32
pred = ... #shape (3000,1,30) dtype float32

cnf_matrix = confusion_matrix(val, pred) #ERROR HERE

我收到了这个错误:

Traceback(最近一次调用最后一次):文件“vis.py”,第 757 行,在 cnf_matrix=confusion_matrix(y_test, y_pred) 文件 "C:\Anaconda\envs\nn35\lib\site-packages\sklearn\metrics\classification.py", 第 240 行,在混淆矩阵中 y_type, y_true, y_pred = _check_targets(y_true, y_pred) 文件 "C:\Anaconda\envs\nn35\lib\site-packages\sklearn\metrics\classification.py", 第 89 行,在 _check_targets 中 raise ValueError("{0} is not supported".format(y_type)) ValueError: unknown is not supported

我做错了什么?

【问题讨论】:

    标签: scikit-learn


    【解决方案1】:

    问题是真实值的形状,预测必须是 (3000,30) 而不是 (3000,1,30)。所以我用pred= np.reshape(pred, (pred.shape[0], 30))重塑它

    【讨论】:

      猜你喜欢
      • 2016-05-12
      • 2018-05-22
      • 1970-01-01
      • 2014-06-11
      • 2020-05-30
      • 2019-02-12
      • 2020-07-16
      • 1970-01-01
      • 2020-05-31
      相关资源
      最近更新 更多