我用线性回归来预测房价(https://www.kaggle.com/c/house-prices-advanced-regression-techniques/overview)。我的线性回归有时对0.8的R^2很有效,有时对- 20000000000000的R^2很糟糕(是的,真的很糟糕)。我的数据是缩放的(使用Min),但我的目标值不是。这个问题在缩放之前也出现了。显然,我的预测只有几次失败,但实际上是错误的。
这是我的代码:
df = pd.read_csv('data/results/house_prices_advanced_regression/house_prices_advanced_regression_.csv')
target = df['SalePrice']
df = df.drop('SalePrice', axis=1)
x_train, x_test, y_train, y_test = train_test_split(df, target, test_size=0.2)
# model
lr = LinearRegression().fit(x_train, y_train)
predictions = lr.predict(x_test)
rmse = mean_squared_error(y_test, predictions, squared=False)
mae = mean_absolute_error(y_test, predictions)
print('RMSE: {}'.format(rmse))
print('MAE: {}'.format(mae))
x = range(len(y_test))
plt.plot(x, predictions, 'r')
plt.plot(x, y_test, 'b')
print("R^2: {}".format(lr.score(x_test, y_test)))输出:
'RMSE: 4.2834860573491624e+16'
'MAE: 3483821398471256.5'
'R^2: -3.358286170039772e+23'预测值(红色)和真实值(蓝色)之间的差异:

系数:

有人知道该怎么做吗?
发布于 2021-05-24 19:15:25
有许多方法试图改进模型,但更重要的是了解正在发生的事情。
首先,您已经显示了一个具有200多个“功能”的图形,尽管对输入进行了缩放,但系数的顺序是1E17!编辑:房价(以美元计)在1E5-E7之间,即不到1000万美元,但系数至少有7个数量级大或小。
因此,共同采取或合并采取的两个直接步骤是行为:
当我们现在进入“超级参数”调优的世界时,不要忘记将数据分成3部分,而不是2部分。
https://datascience.stackexchange.com/questions/94831
复制相似问题