机器学习专栏:机器学习专栏
from sklearn.metrics import mean_squared_error
from sklearn.metrics import r2_score
explained_variance_score(y_true, y_pred, sample_weight=None, multioutput=‘uniform_average’)
mean_absolute_error(y_true,y_pred,sample_weight=None,multioutput=‘uniform_average’)
mean_squared_error(y_true,y_pred,sample_weight=None,multioutput=‘uniform_average’)
median_absolute_error(y_true, y_pred)
r2_score(y_true,y_pred,sample_weight=None,multioutput=‘uniform_average’)
accuracy_score(y_true,y_pre)
auc(x, y, reorder=False)
average_precision_score(y_true, y_score, average=‘macro’, sample_weight=None)
confusion_matrix(y_true, y_pred, labels=None, sample_weight=None)
F1 = 2 * (precision * recall) / (precision + recall)
precision(查准率)=TP/(TP+FP)
recall(查全率)=TP/(TP+FN)
precision_score(y_true, y_pred, labels=None, pos_label=1, average=‘binary’)
recall_score(y_true, y_pred, labels=None, pos_label=1, average=‘binary’, sample_weight=None)
f1_score(y_true, y_pred, labels=None, pos_label=1, average=‘binary’, sample_weight=None)
log_loss(y_true, y_pred, eps=1e-15, normalize=True, sample_weight=None, labels=None)
roc_auc_score(y_true, y_score, average=‘macro’, sample_weight=None)
ROC曲线越接近左上角,代表模型越好,即ACU接近1
def plot_roc(labels, predict_prob):
false_positive_rate, true_positive_rate, thresholds = roc_curve(labels, predict_prob)
roc_auc = auc(false_positive_rate, true_positive_rate)
plt.title('ROC')
plt.plot(false_positive_rate, true_positive_rate,'b',label='AUC = %0.4f'% roc_auc)
plt.legend(loc='lower right')
plt.plot([0,1],[0,1],'r--')
plt.ylabel('TPR')
plt.xlabel('FPR')
plt.show()