我正在尝试使用Python statsmodels运行多元线性回归。我想确保我做的正确。我有20个预测变量,我将它们用于风速观测。我想在2015年训练我的模型,然后使用2016年的预测来验证我的模型。这是最好的方法吗?
##############Train MOS model##################
#This x20 list grabs the predictors just from 2015
x20=[predictor1[:-(num_verifydays)*24],predictor2[:-
(num_verifydays)*24],predictor3[:-(num_verifydays)*24],predictor4[:-(num_verifydays)*24],predictor5[:-(num_verifydays)*24],predictor6[:-(num_verifydays)*24],predictor7[:-(num_verifydays)*24],predictor8[:-(num_verifydays)*24],predictor9[:-(num_verifydays)*24],predictor10[:-(num_verifydays)*24],predictor11[:-(num_verifydays)*24],predictor12[:-(num_verifydays)*24],predictor13[:-(num_verifydays)*24],predictor14[:-(num_verifydays)*24],predictor15[:-(num_verifydays)*24],predictor16[:-(num_verifydays)*24],predictor17[:-(num_verifydays)*24],predictor18[:-(num_verifydays)*24],predictor19[:-(num_verifydays)*24],predictor20[:-(num_verifydays)*24]]
x20 = np.asarray(x20).T.tolist()
x20 = sm.add_constant(x20)
model20 = sm.OLS(result_full['obs'][:-(num_verifydays)*24],x20, missing='drop').fit()
##################predict with regression model##################
#This x20 list grabs the predictors just from 2016
x20=[predictor1[-(num_verifydays)*24:],predictor2[-(num_verifydays)*24:],predictor3[-(num_verifydays)*24:],predictor4[-(num_verifydays)*24:],predictor5[-(num_verifydays)*24:],predictor6[-(num_verifydays)*24:],predictor7[-(num_verifydays)*24:],predictor8[-(num_verifydays)*24:],predictor9[-(num_verifydays)*24:],predictor10[-(num_verifydays)*24:],predictor11[-(num_verifydays)*24:],predictor12[-(num_verifydays)*24:],predictor13[-(num_verifydays)*24:],predictor14[-(num_verifydays)*24:],predictor15[-(num_verifydays)*24:],predictor16[-(num_verifydays)*24:],predictor17[-(num_verifydays)*24:],predictor18[-(num_verifydays)*24:],predictor19[-(num_verifydays)*24:],predictor20[-(num_verifydays)*24:]]
x20 = np.asarray(x20).T.tolist()
x20 = sm.add_constant(x20)
results = model20.predict(x20)