其实就是MSE加了个根号,这样数量级上比较直观,比如RMSE=10,可以认为回归效果相比真实值平均相差10
# MSE, MAE, R2, RMSE法一
from sklearn.metrics import mean_squared_error #MSE
from sklearn.metrics import mean_absolute_error #MAE
from sklearn.metrics import r2_score#R 2
#调用
mean_squared_error(y_test,y_predict)
mean_absolute_error(y_test,y_predict)
np.sqrt(mean_squared_error(y_test,y_predict)) # RMSE
r2_score(y_test,y_predict)
# MSE, MAE, R2, RMSE法二
from sklearn import metrics
metrics.mean_squared_error(y_test,y_predict)
metrics.mean_absolute_error(y_test,y_predict)
np.sqrt(metrics.mean_squared_error(y_test,y_predict)) # RMSE
metrics.r2_score(y_test,y_predict)
# MAPE和SMAPE
def mape(y_true, y_pred):
return np.mean(np.abs((y_pred - y_true) / y_true)) * 100
def smape(y_true, y_pred):
return 2.0 * np.mean(np.abs(y_pred - y_true) / (np.abs(y_pred) + np.abs(y_true))) * 100
# 调用
mape(y_true, y_pred)
smape(y_true, y_pred)
参考文献:
https://blog.csdn.net/skullFang/article/details/79107127
https://blog.csdn.net/guolindonggld/article/details/87856780