# 预测评价指标RMSE、MSE、MAE、MAPE、SMAPE

### MSE

M S E = 1 n ∑ i = 1 n ( y ^ i − y i ) 2 MSE=\frac{1}{n} \sum_{i=1}^{n} (\hat{y}_i - y_i)^2

### RMSE

R M S E = 1 n ∑ i = 1 n ( y ^ i − y i ) 2 RMSE=\sqrt{\frac{1}{n} \sum_{i=1}^{n} (\hat{y}_i - y_i)^2}

### MAE

M A E = 1 n ∑ i = 1 n ∣ y ^ i − y i ∣ MAE=\frac{1}{n} \sum_{i=1}^{n} |\hat{y}_i - y_i|

### MAPE

M A P E = 100 % n ∑ i = 1 n ∣ y ^ i − y i y i ∣ MAPE=\frac{100\%}{n}\sum_{i=1}^n \left |\frac{ \hat{y}_i - y_i }{ y_i } \right |

### SMAPE

S M A P E = 100 % n ∑ i = 1 n ∣ y ^ i − y i ∣ ( ∣ y ^ i ∣ + ∣ y i ∣ ) / 2 SMAPE=\frac{100\%}{n}\sum_{i=1}^n \frac{ |\hat{y}_i - y_i| }{ (|\hat{y}_i| + |y_i|)/2 }

### Python代码

# coding=utf-8
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%


09-07 3761

09-03 1万+
04-19 3141
12-30 191
12-06 2541
09-06 1万+
06-17 4万+
02-21 21万+
01-30 5297
01-19 12万+
04-25 2万+
©️2020 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客