赞
踩
sklearn.metrics.accuracy_score
import numpy as np
from sklearn.metrics import accuracy_score
y_pred = [0, 1, 0, 1]
y_true = [0, 1, 1, 1]
print('ACC:',accuracy_score(y_true, y_pred))
#ACC:0.75
sklearn.metrics.precision_score
from sklearn import metrics
y_pred = [0, 1, 0, 0]
y_true = [0, 1, 0, 1]
print('Precision',metrics.precision_score(y_true, y_pred))
#Precision 1.0
sklearn.metrics.recall_score
from sklearn import metrics
y_pred = [0, 1, 0, 0]
y_true = [0, 1, 0, 1]
print('Recall',metrics.recall_score(y_true, y_pred))
#Recall 0.5
sklearn.metrics.f1_score
from sklearn import metrics
y_pred = [0, 1, 0, 0]
y_true = [0, 1, 0, 1]
print('Recall',metrics.f1_score(y_true, y_pred))
#F1-score 0.6666666666666666
sklearn.metrics.roc_auc_score
import numpy as np
from sklearn.metrics
import roc_auc_score
y_true = np.array([0, 0, 1, 1])
y_scores = np.array([0.1, 0.4, 0.35, 0.8])
print('AUC socre:',roc_auc_score(y_true, y_scores))
#AUC socre: 0.75
import numpy as np from sklearn import metrics # MAPE需要自己实现 def mape(y_true, y_pred): return np.mean(np.abs((y_pred - y_true) / y_true)) y_true = np.array([1.0, 5.0, 4.0, 3.0, 2.0, 5.0, -3.0]) y_pred = np.array([1.0, 4.5, 3.8, 3.2, 3.0, 4.8, -2.2]) # MSE print('MSE:',metrics.mean_squared_error(y_true, y_pred)) # RMSE print('RMSE:',np.sqrt(metrics.mean_squared_error(y_true, y_pred))) # MAE print('MAE:',metrics.mean_absolute_error(y_true, y_pred)) # MAPE print('MAPE:',mape(y_true, y_pred)) #MSE: 0.2871428571428571 #RMSE: 0.5358571238146014 #MAE: 0.4142857142857143 #MAPE: 0.1461904761904762
from sklearn.metrics import r2_score
y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]
print('R2-score:',r2_score(y_true, y_pred))
#R2-score: 0.9486081370449679
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。