赞
踩
以五分类为例:
根据测试集数据计算得出如下几个数组:
y_true:存放的是测试集数据的真实标签,数组形状 [test_size],数据类型 int,值属于{0,1,2,3,4}
y_true_onehot:存放的是测试集数据的真实标签, 数组形状 [test_size, num_class](num_class=5); 数据类型 int(值为0或1),0代表不属于,1代表属于;
y_score: 存放的是分类模型计算出的概率,数组形状 [test_size, num_class](num_class=5); 数据类型 float(值为计算出的概率);
y_pred: 与y_true形式相同的数组,只不过内部的值是通过网络预测出来的类别。根据y_score得出的预测结果(类别).
首先在代码顶部导入
from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score, roc_auc_score
1. accuracy
acc = accuracy_score(y_true, y_pred)
2. F1
f1_every_class = f1_score(y_true, y_pred, average=None)
f1_macro = f1_score(y_true, y_pred, average='macro')
f1_micro = f1_score(y_true, y_pred, average='micro')
3. precision
precision_every_class = precision_score(y_true, y_pred,average=None)
precision_macro = precision_score(y_true,y_pred, average='macro')
precision_micro = precision_score(y_true, y_pred, average='micro')
4. recall
recall_every_class = recall_score(y_true, y_pred, average=None)
recall_macro = recall_score(y_true, y_pred, average='macro')
recall_micro = recall_score(y_true, y_pred, average='micro')
5. auc
auc_every_class = roc_auc_score(y_true_onehot,y_score,average = None)
auc_macro = roc_auc_score(y_true_onehot,y_score,average='macro')
auc_micro = roc_auc_score(y_true_onehot,y_score,average='micro')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。