XDZhelheim / STAEformer

[CIKM'23] Official code for our paper "Spatio-Temporal Adaptive Embedding Makes Vanilla Transformer SOTA for Traffic Forecasting".
https://arxiv.org/abs/2308.10425
132 stars 16 forks source link

请问计算MAE和RMSE的方法中mask的作用是什么? #17

Closed lelelelelelelelelelelelelelele closed 3 weeks ago

lelelelelelelelelelelelelelele commented 3 weeks ago

真实数据y_true中原本就含有0,mask可能会隐去数值为0的那部分数据的误差吧

def RMSE(y_true, y_pred):
    with np.errstate(divide="ignore", invalid="ignore"):
        mask = np.not_equal(y_true, 0)
        mask = mask.astype(np.float32)
        mask /= np.mean(mask)
        rmse = np.square(np.abs(y_pred - y_true))
        rmse = np.nan_to_num(rmse * mask)
        rmse = np.sqrt(np.mean(rmse))
        return rmse
def MAE(y_true, y_pred):
    with np.errstate(divide="ignore", invalid="ignore"):
        mask = np.not_equal(y_true, 0)
        mask = mask.astype(np.float32)
        mask /= np.mean(mask)
        mae = np.abs(y_pred - y_true)
        mae = np.nan_to_num(mae * mask)
        mae = np.mean(mae)
        return mae
XDZhelheim commented 3 weeks ago

你好!你理解的基本没问题。mask是忽略真实值为0的情况,0值代表原始数据的缺失(主要是METRLA数据集缺失多)。用缺失的数据训练模型显然不合理,所以常见的做法是在loss和metric里都mask掉了。

lelelelelelelelelelelelelelele commented 3 weeks ago

非常感谢您的解答!