Closed lelelelelelelelelelelelelelele closed 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
你好!你理解的基本没问题。mask是忽略真实值为0的情况,0值代表原始数据的缺失(主要是METRLA数据集缺失多)。用缺失的数据训练模型显然不合理,所以常见的做法是在loss和metric里都mask掉了。
非常感谢您的解答!
真实数据y_true中原本就含有0,mask可能会隐去数值为0的那部分数据的误差吧