Evaluation of the effectiveness of classification algorithms
1,准确率accuracy_score
from sklearn.metrics import accuracy_score
2. Precision rate/precision rate precision_score
from sklearn.metrics import precision_score is
divided into macro average (macro) and micro average (micro), macro average is more reasonable than micro average.
metrics.precision_score(y_true, y_pred, average='micro')
metrics.precision_score(y_true, y_pred, average='macro')
There are five types of average parameters: (None,'micro','macro','weighted', 'samples')
3. Recall rate/recall rate recall_score
from sklearn.metrics import recall_score The
recall rate also has the difference between macro average and micro average, and the usage is the same as above.
4,F1-score
from sklearn.metrics import f1_score
metrics.f1_score(y_true, y_pred, average='weighted')
5,混淆矩阵(confusion-matrix)
from sklearn.metrics import confusion_matrix
6. Classification report (classification_report)
from sklearn.metrics import classification_report
contains precision/recall/f1-score/mean/number of classifications
7,kappa score
from sklearn.metrics import cohen_kappa_score
cohen_kappa_score(y_true, y_pred)
8. ROC
1) Calculate the ROC value
from sklearn.metrics import roc_auc_score
roc_auc_score(y_true, y_scores)
2)
Draw ROC diagram For the method of drawing ROC diagram, please refer to the official code
http://scikit-learn.org/stable/ auto_examples/model_selection/plot_roc.html
9,距离
1)海明距离(hamming_loss)
from sklearn.metrics import hamming_loss
hamming_loss(y_true, y_pred)
2)Jaccard距离(jaccard_similarity_score)
from sklearn.metrics import jaccard_similarity_score
jaccard_similarity_score(y_true, y_pred)
Evaluation index of regression algorithm
1.
Explainable variance is also called explained variance (explained_variance_score) from sklearn.metrics import explained_variance_score
explained_variance_score(y_true, y_pred)
2,平均绝对误差(mean_absolute_error)
from sklearn.metrics import mean_absolute_error
mean_absolute_error(y_true, y_pred)
3,均方误差(mean_squared_error)
from sklearn.metrics import mean_squared_error
mean_squared_error(y_true, y_pred)
4,中值绝对误差(median_absolute_error)
from sklearn.metrics import median_absolute_error
median_absolute_error(y_true, y_pred)
5. R square value, coefficient of determination (r2_score)
from sklearn.metrics import r2_score
r2_score(y_true, y_pred)
Author: Xi Bao
link: https: //www.jianshu.com/p/c3cf5c6081ad
Source: Jane books
are copyrighted by the author. For commercial reprints, please contact the author for authorization, and for non-commercial reprints, please indicate the source.