我正在尝试使用sklean包的classification_report模块来评估多类分类模型。
Y_pred维度:(1000,36) y_test维度:(1000,36)
我尝试在两个阵列上调用classification_report,即y_test和y_pred
def display_results(y_test,y_pred,column_name=labels):
print(classification_report(y_test,y_pred,target_names=labels))使用下面的代码,我得到:
ValueError: Unknown label type: (array([[1, 0, 0, ..., 0, 0, 0],
[1, 0, 0, ..., 0, 0, 0],
[1, 0, 0, ..., 1, 1, 0],
...,
[1, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[1, 0, 0, ..., 0, 0, 0]]), array([[1, 0, 0, ..., 0, 0, 0],
[1, 0, 0, ..., 0, 0, 0],
[1, 0, 0, ..., 0, 0, 0],
...,
[1, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[1, 0, 0, ..., 0, 0, 0]]))我希望得到基于传递给函数的标签的精确度、召回率、F1和所有列的总平均指标。
发布于 2019-10-28 01:10:05
对于您的错误,需要np.hstack
在分类器具有多类多输出的情况下效果最佳
from sklearn.utils.multiclass import type_of_target
type_of_target(y_test)
type_of_target(y_pred)
>>'multiclass-multioutput'所以,你的解决方案是
print(classification_report(np.hstack(y_test),np.hstack(y_pred)))https://stackoverflow.com/questions/56826216
复制相似问题