MAE、MSE 和 MAPE 没有可比性?

数据挖掘 数据挖掘 熊猫 支持向量机 麻木的
2022-02-19 17:50:32

我是数据科学的新手。我正在研究回归问题。我得到 2.5 MAPE。400 MAE 437000 MSE。因为我的 MAPE 很低,但为什么我的 MSE 和 MAE 却很高? 是我的数据的链接

from sklearn.metrics import mean_absolute_error 
from sklearn.metrics import mean_squared_error
from sklearn.preprocessing import Normalizer
import matplotlib.pyplot as plt
def mean_absolute_percentage_error(y_true, y_pred): 
    y_true, y_pred = np.array(y_true), np.array(y_pred)
    return np.mean(np.abs((y_true - y_pred) / y_true)) * 100

import pandas as pd
from sklearn import preprocessing

features=pd.read_csv('selectedData.csv')
import numpy as np
from scipy import stats
print(features.shape)
features=features[(np.abs(stats.zscore(features)) < 3).all(axis=1)]
target = features['SYSLoad']
features= features.drop('SYSLoad', axis = 1)
names=list(features)

for i in names:
    x=features[[i]].values.astype(float)
    min_max_scaler = preprocessing.MinMaxScaler()
    x_scaled = min_max_scaler.fit_transform(x)
    features[i]=x_scaled

选择要预测的目标变量,我们正在寻找特征 imps

import numpy as np
print(features.shape)
print(features.describe())
from sklearn.model_selection import train_test_split
train_input, test_input, train_target, test_target = 
train_test_split(features, target, test_size = 0.25, random_state = 42)
trans=Normalizer().fit(train_input);
train_input=Normalizer().fit_transform(train_input);
test_input=trans.fit_transform(test_input);

n=test_target.values;
test_targ=pd.DataFrame(n);

from sklearn.svm import SVR
svr_rbf = SVR(kernel='poly', C=10, epsilon=10,gamma=10)
y_rbf = svr_rbf.fit(train_input, train_target);
predicted=y_rbf.predict(test_input);
plt.figure
plt.xlim(300,500);
print('Total Days For training',len(train_input)); print('Total Days For 
Testing',len(test_input))
plt.ylabel('Load(MW) Prediction 3 '); plt.xlabel('Days'); 
plt.plot(test_targ,'-b',label='Actual'); plt.plot(predicted,'-r',label='POLY 
kernel ');
plt.gca().legend(('Actual','RBF'))
plt.title('SVM')
plt.show();


test_target=np.array(test_target)
print(test_target)
MAPE=mean_absolute_percentage_error(test_target,predicted);
print(MAPE);
mae=mean_absolute_error(test_target,predicted)
mse=mean_squared_error(test_target, predicted)
print(mae);
print(mse);
print(test_target);
print(predicted);
2个回答

老实说,我还没有彻底检查你的代码。但是,我可以看到您的数据集的值范围约为[0,12000]作为一名工程师,我认为:

  1. sqrt(MSE) = sqrt(437000) = 661 个单位。
  2. MAE = 400 单位。
  3. MAPE = 2.5,这意味着 MAE 可以达到 0.025*12000= 250 个单位。

所有这三种情况都显示出相似的误差幅度,所以我不会说“MAPE 很低,但你的 mse 和 MAE 很高”。

这三个值从相似但不同的角度解释了结果。请记住,如果值都相同,则不需要所有 3 个指标都存在 :)

您正在陈述一些根据定义就是这种情况的事情。平均绝对百分比误差 (MAPE) 通常是一个以百分比表示的小数字,希望是个位数。同时,均方误差 (MSE) 和平均绝对误差) 分别以单位和单位的平方表示。如果您的单位 > 1,则相对于 MAE,MSE 很容易变得非常大。而且,MAE 也可能比 MAPE 大很多。这就像说一个名义数字比它的对数或自然对数大很多一样。您的三个错误度量是在完全不同的规模上测量的。

它们只是为您的模型与数据的拟合程度提供了一些视角。根据情况或上下文,一种错误度量可能比另一种更相关。