线性回归R平方为1.0

问题描述

我正在Python上执行线性回归,以预测分布在象牙海岸各个站点的库存。我有2016年至2019年9月的数据,看起来像

DATA

。列为

Dataset_info

。 我在网站代码上使用了标签编码。有156个不同的站点,每个站点的标记范围为0-155。同样,我使用Get_dummies函数为11种不同的产品代码获取11种不同的列。 然后,我使用线性回归来帮助预测输出,令我惊讶的是,R平方值为100%。 代码:


lm=sm.OLS(df_logistics_new_onehot_label['stock_distributed'],df_logistics_new_onehot_label[['intercept','year','month','site_code','stock_initial','stock_received','stock_adjustment','stock_end','average_monthly_consumption','stock_stockout_days','stock_ordered','site_latitude','site_longitude','product_code_AS21126','product_code_AS27000','product_code_AS27132','product_code_AS27133','product_code_AS27134','product_code_AS27137','product_code_AS27138','product_code_AS27139','product_code_AS42018','product_code_AS46000','site_type_Health Center','site_type_University Hospital/National Institute']])

results=lm.fit()
results.summary()

回归的输出看起来像这样

Regression Output

我进一步将数据分为训练和测试

X=df_logistics_new_onehot_label[['intercept','site_type_University Hospital/National Institute']]
y=df_logistics_new_onehot_label['stock_distributed']

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size = 0.2,shuffle=False)

clf=LinearRegression()

clf.predict(X_test)

线性回归的20%数据输出与“库存分配”变量完全匹配,如您在此处看到的

Output V/s data

是模型过度拟合还是我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)