我想预测一次旅行所需的时间。为此,我将因变量(以秒为单位的行程时间)转换为对数转换。
当我使用其他一些特征对该变量进行回归时,
我明白了:
The score on held out data is: 0.08395386395024673
Hyper-Parameters for Best Score : {'l1_ratio': 0.15, 'alpha': 0.01}
The R2 Score of sgd_regressor on test data is: 0.0864573982691922
The mse of sgd_regressor on test data is: 0.5503753581
The mean absolute error of sgd_regressor on test data is: 0.566328128068
这是执行上述计算的代码:
from sklearn.metrics import mean_squared_error, mean_absolute_error
#
print("The R2 Score of "+ name + " on test data is: {}\n".format(self.g_cv.best_estimator_.score(self.test_X,self.test_Y)))
print ("The mse of "+ name + " on test data is:",\
mean_squared_error(test_Y, self.g_cv.best_estimator_.predict(self.test_X)))
print ("The mean absolute error of "+ name + " on test data is:",\
mean_absolute_error(test_Y, self.g_cv.best_estimator_.predict(self.test_X)))
问题是 R2,如您所见,非常糟糕。 0.08,但 RMSE 和平均绝对误差似乎很低。如果我看看平均绝对误差,它只有 0.56 秒。这意味着平均而言我的预测时间与真实时间仅相差半秒。
有些事情看起来不太对劲。在计算上述指标(RMSE 和 MAE)之前,是否需要将预测时间变量和原始时间变量从对数刻度转换回线性刻度?
谢谢
最佳答案
正在根据转换后的变量计算您的指标。
因此,MAE 0.56 是持续时间的对数之间的平均差,而不是持续时间本身。
您可以转换回秒,请记住
log(m) - log(n) = log(m/n)
关于python - 因变量进行对数变换时的回归 RMSE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47373263/