1.绝对误差与相对误差
2.平均绝对误差
>>> from sklearn.metrics import mean_absolute_error
>>> y_true = [3, -0.5, 2, 7]
>>> y_pred = [2.5, 0.0, 2, 8]
>>> mean_absolute_error(y_true, y_pred)
0.5
3.均方误差
>>> from sklearn.metrics import mean_squared_error
>>> y_true = [3, -0.5, 2, 7]
>>> y_pred = [2.5, 0.0, 2, 8]
>>> mean_squared_error(y_true, y_pred)
0.375
4.均方根误差
5.平均绝对百分误差
6.Kappa统计
>>> from sklearn.metrics import cohen_kappa_score
>>> y_true = [2, 0, 2, 2, 0, 1]
>>> y_pred = [0, 0, 2, 2, 0, 2]
>>> cohen_kappa_score(y_true, y_pred)
0.4285714285714286
7.识别准确度
import numpy as np
from sklearn.metrics import accuracy_score
y_pred = [0, 2, 1, 3]
y_true = [0, 1, 2, 3]
accuracy_score(y_true, y_pred)
0.5
8.识别精确度
>>> from sklearn import metrics
>>> y_pred = [0, 1, 0, 0]
>>> y_true = [0, 1, 0, 1]
>>> metrics.precision_score(y_true, y_pred)
1.0
9,召回率
>>> from sklearn import metrics
>>> y_pred = [0, 1, 0, 0]
>>> y_true = [0, 1, 0, 1]
>>> metrics.recall_score(y_true, y_pred)
0.5
10.ROC曲线
def SHOW_ROC(test_label_true, test_label_predict):
"""
:param test_label_true:输入真实标签
:param test_label_predict: 输入测试标签
:return:
"""
# 计算ROC曲线的x轴和y轴的数据
fpr, tpr, _ = metrics.roc_curve(test_label_true, test_label_predict)
# 绘制ROC曲线
plt.plot(fpr, tpr, linestyle='solid', color='red')
# 添加阴影
# plt.stackplot(fpr, tpr, color = 'streeblue')
# 绘制参考线
plt.plot([0, 1], [0, 1], linestyle='dashed', color='black')
# 向图中添加文本
plt.text(0.6, 0.4, 'AUC=%.3f' % metrics.auc(fpr, tpr), fontdict=dict(size=18))
plt.show()
11.混淆矩阵
>>> from sklearn.metrics import confusion_matrix
>>> y_true = [2, 0, 2, 2, 0, 1]
>>> y_pred = [0, 0, 2, 2, 0, 2]
>>> confusion_matrix(y_true, y_pred)
array([[2, 0, 0],
[0, 0, 1],
[1, 0, 2]])