问题描述
我的数据框有8列( target_var ='I62')。当我运行python大熊猫 corr()时,它为我的target_var与 IOF2和H6 之间提供了很好的关联。
# This data is till 2019-Dec
df3Train = pd.read_csv('I62Trainv7.csv',parse_dates=['Value_Date'],index_col=['Value_Date'])
df3Train.corr()
请参见下图 Correlation
使用“ I62”(y)和“ [IOF2,H6]”(x),我从sklearn创建了LinearRegression模型。当我在寻找模型的系数时,它显示出H6的负(-0.004)系数:
# Model building with I62 and IOF2 and H6
y = df3TrainClean["I62"]
# Independent Vars
x = df3TrainClean[['IOF2','H6']]
# Training on 80% Testing 20%
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.20,random_state=1)
lrModel = LinearRegression()
lrModel.fit(x_train,y_train)
print(lrModel.score(x_test,y_test))
print(lrModel.score(x_train,y_train))
# Lets train the model
lrModel.fit(x,y)
yPred = lrModel.predict(x_test)
# Coefficients
coeff_df = pd.DataFrame(lrModel.coef_,x.columns,columns=['Coefficient'])
coeff_df
我有点迷失了,当存在良好的相关性时,系数怎么会过低(并且容易使人联想)! 任何人都可以请解释一下这个变量以及它对预测的影响。
谢谢
解决方法
负相关表示当一个值增加时,另一个值减少。相关可以取值为-1,这意味着两个值始终沿相反的方向移动。相关性为0表示一个运动并不意味着另一个运动-即它们根本不相关。