MSE
均方误差(Mean Square Error) \(M S E=\frac{1}{n} \sum_{i=1}^{n}\left(\hat{y}_{i}-y_{i}\right)^{2}\) 值的范围是(0, 无穷大),当预测值与真实值完全一样的时候等于0,值越大表示误差越大
RMSE
均方根误差(Root Mean Square Error) \(R M S E=\sqrt{\frac{1}{n} \sum_{i=1}^{n}\left(\hat{y}_{i}-y_{i}\right)^{2}}\) 在MSE的基础上加上根号,在数量级上比较直观。值的范围也是(0, 无穷大),
MAE
平均绝对误差(Mean Absolute Error) \(M A E=\frac{1}{n} \sum_{i=1}^{n}\left|\hat{y}_{i}-y_{i}\right|\) 值的范围是(0, 无穷大),
MAPE
平均绝对百分比误差(Mean Absolute Percentage Error) \(M A P E=\frac{100 \%}{n} \sum_{i=1}^{n}\left|\frac{\hat{y}_{i}-y_{i}}{y_{i}}\right|\) 值的范围是(0, 无穷大),注意当真实值为0,存在分母为0的情况,不可用
SMAPE
对称平均绝对百分比误差(Symmetric Mean Absolute Percentage Error) \(S M A P E=\frac{100 \%}{n} \sum_{i=1}^{n} \frac{\left|\hat{y}_{i}-y_{i}\right|}{\left(\left|\hat{y}_{i}\right|+\left|y_{i}\right|\right) / 2}\)
代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import numpy as np
from sklearn import metrics
# 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
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.5, 5.0, 8.0, 4.5, 1.0])
# MSE
print(metrics.mean_squared_error(y_true, y_pred)) # 8.107142857142858
# RMSE
print(np.sqrt(metrics.mean_squared_error(y_true, y_pred))) # 2.847304489713536
# MAE
print(metrics.mean_absolute_error(y_true, y_pred)) # 1.9285714285714286
# MAPE
print(mape(y_true, y_pred)) # 76.07142857142858,即76%
# SMAPE
print(smape(y_true, y_pred)) # 57.76942355889724,即58%
参考
1.评测指标