Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用拟合的statsmodel GLMgam模型对新数据进行预测?_Python_Statsmodels - Fatal编程技术网

Python 如何使用拟合的statsmodel GLMgam模型对新数据进行预测?

Python 如何使用拟合的statsmodel GLMgam模型对新数据进行预测?,python,statsmodels,Python,Statsmodels,运行statsmodel包的GLMgam类文档中的示例的代码后 from statsmodels.gam.api import GLMGam, BSplines from statsmodels.gam.tests.test_penalized import df_autos df_autos_train = df_autos.iloc[0:165] df_autos_test = df_autos.iloc[165:205] x_spline = df_autos_train[['weight

运行statsmodel包的GLMgam类文档中的示例的代码后

from statsmodels.gam.api import GLMGam, BSplines
from statsmodels.gam.tests.test_penalized import df_autos
df_autos_train = df_autos.iloc[0:165]
df_autos_test = df_autos.iloc[165:205]
x_spline = df_autos_train[['weight', 'hp']]
bs = BSplines(x_spline, df=[12, 10], degree=[3, 3])
alpha = np.array([21833888.8, 6460.38479])
gam_bs = GLMGam.from_formula('city_mpg ~ fuel + drive', data=df_autos_train, smoother=bs, alpha=alpha)
res_bs = gam_bs.fit()
print(res_bs.summary())
我没有得到这个预言

res_bs.predict(exog = df_autos_test[['fuel', 'drive']], exog_smooth = df_autos_test[['weight', 'hp']])
告诉我错误

File "pandas\_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 116, in pandas._libs.index.IndexEngine.get_loc
TypeError: '(slice(None, None, None), 0)' is an invalid key

可能是熊猫支持中的一个错误<代码>exog_smooth=np.asarray(df_autos_test[['weight','hp']])适合我。谢谢你提供了一个可以立即运行的示例。很好,谢谢!我觉得有点傻,我确信我已经尝试过了(使用.values)。问题解决了,再次感谢你们!