一、分类
1、准确率:
sklearn.metrics.accuracy_score(y_true, y_pred, normalize=True)
##参数normalize:默认值为True,返回正确分类的比例;如果为False,返回正确分类的样本数
2、召回率/查全率:
sklearn.metrics.recall_score(y_true, y_pred, average='binary')
##参数average : string, [None, ‘micro’, ‘macro’(default), ‘samples’, ‘weighted’],多分类时可用其它参数
3、ROC曲线
sklearn.metrics.roc_curve(y_true,y_score,pos_label=2)
##该函数返回这三个变量:fpr,tpr,和阈值thresholds;
4、AUC
① sklearn.metrics.roc_auc_score(y_true, y_score, average='macro', sample_weight=None)
② fpr,tpr,thresholds=sklearn.metrics.roc_curve(y_true,y_score)
sklearn.metrics.auc(fpr,tpr)
5、混淆矩阵
sklearn.metrics.confusion_matrix(y_true, y_pred, labels=None)
##labels:混淆矩阵的索引,用于选择矩阵维度,默认None表示完全展示
def cm_plot(y, yp):
'''画混淆矩阵图'''
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y, yp) #混淆矩阵
import matplotlib.pyplot as plt #导入作图库
plt.matshow(cm, cmap=plt.cm.Greens) #画混淆矩阵图,配色风格使用cm.Greens,更多风格请参考官网。
plt.colorbar() #颜色标签
for x in range(len(cm)): #数据标签
for y in range(len(cm)):
plt.annotate(cm[x,y], xy=(y, x), horizontalalignment='center', verticalalignment='center')
plt.ylabel('True label') #坐标轴标签
plt.xlabel('Predicted label') #坐标轴标签
return plt
6、F1值
sklearn.metrics.f1_score(y_true, y_pred)
7、查准率
sklearn.metrics.precision_score(y_true, y_pred)
二、回归
1、sklearn.metrics.explained_variance_score(y_true, y_pred, sample_weight=None, multioutput='uniform_average'):回归方差(反应自变量与因变量之间的相关程度)
2、sklearn.metrics.mean_absolute_error(y_true, y_pred, sample_weight=None, multioutput='uniform_average'):平均绝对误差
3、sklearn.metrics.mean_squared_error(y_true, y_pred, sample_weight=None, multioutput='uniform_average'):均方差
4、sklearn.metrics.median_absolute_error(y_true, y_pred) 中值绝对误差
5、sklearn.metrics.r2_score(y_true, y_pred, sample_weight=None, multioutput='uniform_average') :R平方值
参考文献:https://www.cnblogs.com/mdevelopment/p/9456486.html