当前位置:   article > 正文

【Python】算法评估指标(sklearn.metrics)_python sklearn.metrics 检测指标

python sklearn.metrics 检测指标

F1,Precision,Recall sklearn.metrics.f1_score/recall_score/precision_score

  1. 预测值与实际值
# keras训练的model
# .predict() 输出预测的值
pre = model.predict(X_test, batch_size=batch_size)
pre, y_test
'''
array([[0.18804531, 0.3357192 , 0.47623548],
        [0.30215347, 0.36785322, 0.32999334],
        [0.18804531, 0.3357192 , 0.47623548],
        [0.18804531, 0.3357192 , 0.47623548],
        [0.18804531, 0.3357192 , 0.47623548],
        [0.30215347, 0.36785322, 0.32999334],
        [0.30215347, 0.36785322, 0.32999334],
        [0.18804531, 0.3357192 , 0.47623548],
        [0.30215347, 0.36785322, 0.32999334]])
array([[1., 0., 0.],
        [1., 0., 0.],
        [0., 1., 0.],
        [1., 0., 0.],
        [0., 1., 0.],
        [1., 0., 0.],
        [0., 1., 0.],
        [0., 0., 1.],
        [1., 0., 0.],
        [0., 1., 0.]])
'''
# 进行转化
for idx1 in range(len(pre)):
    max_val = max(pre[idx1])
    for idx2 in range(len(pre[idx1])):
        if max_val == pre[idx1][idx2]:
            pre[idx1][idx2] = 1
        else:
            pre[idx1][idx2] = 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  1. 评估
from sklearn.metrics import f1_score, recall_score, precision_score

_val_f1 = f1_score(y_true=y_test, y_pred=pre, average='weighted')
_val_recall = recall_score(y_true=y_test, y_pred=pre, average='weighted')
_val_precision = precision_score(y_true=y_test, y_pred=pre, average='weighted')
print(" — val_f1: %f — val_precision: %f — val_recall: %f" % (_val_f1, _val_precision, _val_recall))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/953524
推荐阅读
相关标签
  

闽ICP备14008679号