我有这样的代码
m2=smf.ols(formula='demand~year+C(months)+year*C(months)',data=df).fit()
m2.summary()
一个数据帧,具有三列,144行,需求,在2000-2011年和1-12个月。现在,我想获得基于年与月之间的交互作用的预测值,以此来预测需求(这里将月视为分类变量。该怎么办?
m2.predict( #what should I enter here?)
这里是线性回归的模型。如果有帮助
OLS Regression Results
Dep. Variable: demand R-squared: 0.985
Model: OLS Adj. R-squared: 0.982
Method: Least Squares F-statistic: 343.4
Date: Thu, 08 Oct 2020 Prob (F-statistic): 2.78e-98
Time: 00:38:14 Log-Likelihood: -590.64
No. Observations: 144 AIC: 1229.
Df Residuals: 120 BIC: 1301.
Df Model: 23
Covariance Type: nonrobust
coef std err t P>|t| [0.025 0.975]
Intercept -5.548e+04 2686.757 -20.651 0.000 -6.08e+04 -5.02e+04
C(months)[T.2] 6521.6434 3799.648 1.716 0.089 -1001.396 1.4e+04
C(months)[T.3] 217.7471 3799.648 0.057 0.954 -7305.292 7740.786
C(months)[T.4] -3200.2960 3799.648 -0.842 0.401 -1.07e+04 4322.743
C(months)[T.5] -7465.9988 3799.648 -1.965 0.052 -1.5e+04 57.040
C(months)[T.6] -1.832e+04 3799.648 -4.822 0.000 -2.58e+04 -1.08e+04
C(months)[T.7] -3.072e+04 3799.648 -8.086 0.000 -3.82e+04 -2.32e+04
C(months)[T.8] -3.013e+04 3799.648 -7.929 0.000 -3.77e+04 -2.26e+04
C(months)[T.9] -1.265e+04 3799.648 -3.328 0.001 -2.02e+04 -5122.469
C(months)[T.10] -5374.5897 3799.648 -1.414 0.160 -1.29e+04 2148.449
C(months)[T.11] 3139.5781 3799.648 0.826 0.410 -4383.461 1.07e+04
C(months)[T.12] -1122.9114 3799.648 -0.296 0.768 -8645.950 6400.127
year 27.7867 1.340 20.741 0.000 25.134 30.439
year:C(months)[T.2] -3.2552 1.895 -1.718 0.088 -7.006 0.496
year:C(months)[T.3] -0.0944 1.895 -0.050 0.960 -3.846 3.657
year:C(months)[T.4] 1.6084 1.895 0.849 0.398 -2.143 5.360
year:C(months)[T.5] 3.7378 1.895 1.973 0.051 -0.013 7.489
year:C(months)[T.6] 9.1713 1.895 4.841 0.000 5.420 12.923
year:C(months)[T.7] 15.3741 1.895 8.115 0.000 11.623 19.125
year:C(months)[T.8] 15.0769 1.895 7.958 0.000 11.326 18.828
year:C(months)[T.9] 6.3357 1.895 3.344 0.001 2.584 10.087
year:C(months)[T.10] 2.6923 1.895 1.421 0.158 -1.059 6.444
year:C(months)[T.11] -1.5699 1.895 -0.829 0.409 -5.321 2.181
year:C(months)[T.12] 0.5699 1.895 0.301 0.764 -3.181 4.321
答案 0 :(得分:0)
m2.predict(df.loc[:,['year', 'months']])