Trying to predict on new data using GLMGam, but it's basically impossible, not even with the training dataset ``` import statsmodels.api as sm from statsmodels.gam.api import GLMGam, BSplines # import data from statsmodels.gam.tests.test_penalized import df_autos # create spline basis for weight and hp x_spline = df_autos[['weight', 'hp']] bs = BSplines(x_spline, df=[12, 10], degree=[3, 3]) # penalization weight alpha = np.array([21833888.8, 6460.38479]) gam_bs = GLMGam.from_formula('city_mpg ~ fuel + drive', data=df_autos, smoother=bs, alpha=alpha) res_bs = gam_bs.fit() ``` None of these will work (and at least one whould) ``` gam_bs.predict(df_autos) gam_bs.predict(x_spline) res_bs.predict(df_autos) res_bs.predict(x_spline) res_bs.predict(x_spline) ``` I finally tried with ``` res_bs.predict(bs.transform(x_spline.values)) ``` And it takes AGES (i'm assuming it will finish, because 5 minutes in and it hasn't). It's just 200 samples
Activity
josef-pkt commentedon Oct 29, 2021
based on the docstring https://www.statsmodels.org/dev/generated/statsmodels.gam.generalized_additive_model.GLMGamResults.predict.html
it should be
res_bs.predict(df_autos[['fuel', 'drive']], exog_smooth=df_autos[['weight', 'hp']])or variations on it.
I guess when using formulas, this should work also
res_bs.predict(df_autos, exog_smooth=df_autos[['weight', 'hp']])Where df_autos can be replace with a dataframe with new, out of sample values