Metrics提供以下语言的各种监督机器学习评估指标的实现:
easy_install ml_metrics
install.packages("Metrics")
from the R promptcabal install Metrics
有关更详细的安装说明,请参阅每个实现的 README。
Evaluation Metric(评估指标) | Python | R | Haskell | MATLAB / Octave |
Absolute Error (AE) 绝对误差 | ✓ | ✓ | ✓ | ✓ |
Average Precision at K (APK, AP@K)K 的平均精度 | ✓ | ✓ | ✓ | ✓ |
Area Under the ROC (AUC) | ✓ | ✓ | ✓ | ✓ |
Classification Error (CE) | ✓ | ✓ | ✓ | ✓ |
F1 Score (F1)F1 分数 | ✓ | |||
Gini基尼 | ✓ | |||
Levenshtein | ✓ | ✓ | ✓ | |
Log Loss (LL)对数损失 | ✓ | ✓ | ✓ | ✓ |
Mean Log Loss (LogLoss)平均对数损失 | ✓ | ✓ | ✓ | ✓ |
Mean Absolute Error (MAE)平均绝对误差 | ✓ | ✓ | ✓ | ✓ |
Mean Average Precision at K (MAPK, MAP@K) | ✓ | ✓ | ✓ | ✓ |
Mean Quadratic Weighted Kappa | ✓ | ✓ | ✓ | |
Mean Squared Error (MSE)均方误差 | ✓ | ✓ | ✓ | ✓ |
Mean Squared Log Error (MSLE)均方对数误差 | ✓ | ✓ | ✓ | ✓ |
Normalized Gini归一化基尼 | ✓ | |||
Quadratic Weighted Kappa | ✓ | ✓ | ✓ | |
Relative Absolute Error (RAE)相对绝对误差 | ✓ | |||
Root Mean Squared Error (RMSE)均方根误差 | ✓ | ✓ | ✓ | ✓ |
Relative Squared Error (RSE)相对平方误差 | ✓ | |||
Root Relative Squared Error (RRSE)根相对平方误差 | ✓ | |||
Root Mean Squared Log Error (RMSLE)均方根对数误差 | ✓ | ✓ | ✓ | ✓ |
Squared Error (SE)平方误差 | ✓ | ✓ | ✓ | ✓ |
Squared Log Error (SLE)平方对数误差 | ✓ | ✓ | ✓ | ✓ |
(非详尽无遗,将在未来添加)
scikit-learn.metrics导入与调用
有两种方式导入:
方式一:
from sklearn.metrics import 评价指标函数名称
例如:
from sklearn.metrics import mean_squared_error
from sklearn.metrics import r2_score
调用方式为:直接使用函数名调用
计算均方误差mean squared error
mse = mean_squared_error(y_test, y_pre)
计算回归的决定系数R2
R2 = r2_score(y_test,y_pre)
方式二:
from sklearn import metrics
调用方式为:metrics.评价指标函数名称(parameter)
例如:
计算均方误差mean squared error
mse = metrics.mean_squared_error(y_test, y_pre)
计算回归的决定系数R2
R2 = metrics.r2_score(y_test,y_pre)
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’) :R平方值
accuracy_score(y_true,y_pre) : 精度
auc(x, y, reorder=False) : ROC曲线下的面积;较大的AUC代表了较好的performance。
average_precision_score(y_true, y_score, average=‘macro’, sample_weight=None):根据预测得分计算平均精度(AP)
brier_score_loss(y_true, y_prob, sample_weight=None, pos_label=None):The smaller the Brier score, the better.
confusion_matrix(y_true, y_pred, labels=None, sample_weight=None):通过计算混淆矩阵来评估分类的准确性 返回混淆矩阵
f1_score(y_true, y_pred, labels=None, pos_label=1, average=‘binary’, sample_weight=None): F1值
F1 = 2 * (precision * recall) / (precision + recall) precision(查准率)=TP/(TP+FP) recall(查全率)=TP/(TP+FN)
log_loss(y_true, y_pred, eps=1e-15, normalize=True, sample_weight=None, labels=None):对数损耗,又称逻辑损耗或交叉熵损耗
precision_score(y_true, y_pred, labels=None, pos_label=1, average=‘binary’,) :查准率或者精度; precision(查准率)=TP/(TP+FP)
recall_score(y_true, y_pred, labels=None, pos_label=1, average=‘binary’sample_weight=None):查全率 ;recall(查全率)=TP/(TP+FN)
roc_auc_score(y_true, y_score, average=‘macro’, sample_weight=None):计算ROC曲线下的面积就是AUC的值,the larger the better
roc_curve(y_true, y_score, pos_label=None, sample_weight=None, drop_intermediate=True);计算ROC曲线的横纵坐标值,TPR,FPR TPR = TP/(TP+FN) = recall(真正例率,敏感度) FPR = FP/(FP+TN)(假正例率,1-特异性)