You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG(?): GLMGam fit_regularized needs handling of 1D np array #6506
It looks like we iterate through all regressors one by one in fit_regularized (i.e. fit_elasticnet). For each iteration, we initialize a GAM with that regressor and pass in a numpy 1darray of shape (nobs, ).
The problem is that when initializing GAM with single regressor, you're trying to call .shape[1] on the numpy 1darray (sttasmodels/gam/generalized_additive_model.py, line 529 to 531). Don't we need to make this 2d before calling shape[1], similar to what is done in statsmodels/base/model.py at line 1092-1097?
Specifically in line 1097 of model.py, there is a comment: "needed in count model shape[1]"
However, I'm not sure whether it makes sense to use glmnet fit_regularized with GAM, I guess not.
GLMGam uses it's own L2 penalization where the penalization depends on the smoothness, i.e. integrated 2nd derivative of the nonlinear function.
this issue is not just on fit_regularized--it's the 1 dim case for just any GAM that will break, isn't it? though i recognize there may rarely be a use for the 1dim case outside of fit_regularized
test_penalized TestGAM6ExogBfgs is a unit test with a constant only for exog_linear. The test breaks when I used 1-dim constant instead of the current 2-dim constant.
self.data_linear has the data for the linear part from handle_data.
(Pdb) self.data_linear.exog.shape
(133, 1)
This should be used instead of using the user provided exog.
I guess that was incomplete refactoring after adding pandas support to GAM.
fix using data_linear works for TestGAM6ExogBfgs test case
if exog is not None:
exog_linear = self.data_linear.exog
(Aside:
According to code comments, there are still open issues how to handle this in general. currently we use handle_data twice. It might be possible to add missing handling when we do the first handle_data)
Activity
weianwang commentedon Feb 13, 2020
@josef-pkt 65ba8f4
This is the latest iteration, no?
josef-pkt commentedon Feb 13, 2020
The 1-dim case might be a bug.
However, I'm not sure whether it makes sense to use glmnet fit_regularized with GAM, I guess not.
GLMGam uses it's own L2 penalization where the penalization depends on the smoothness, i.e. integrated 2nd derivative of the nonlinear function.
weianwang commentedon Feb 14, 2020
this issue is not just on fit_regularized--it's the 1 dim case for just any GAM that will break, isn't it? though i recognize there may rarely be a use for the 1dim case outside of fit_regularized
josef-pkt commentedon Feb 14, 2020
Yes, it's a bug.
test_penalized TestGAM6ExogBfgsis a unit test with a constant only for exog_linear. The test breaks when I used 1-dim constant instead of the current 2-dim constant.self.data_linearhas the data for the linear part fromhandle_data.This should be used instead of using the user provided exog.
I guess that was incomplete refactoring after adding pandas support to GAM.
josef-pkt commentedon Feb 14, 2020
this is for
predictto create a 2-dim row exog.The data handling for the model endog and exog is delegated to the
dataclasses.josef-pkt commentedon Feb 14, 2020
Thanks for catching this
josef-pkt commentedon Feb 14, 2020
fix using
data_linearworks forTestGAM6ExogBfgstest case(Aside:
According to code comments, there are still open issues how to handle this in general. currently we use handle_data twice. It might be possible to add missing handling when we do the first
handle_data)BUG: fix GAM for 1-dim exog_linear closes statsmodels#6506
josef-pkt commentedon Feb 16, 2020
fix in #6520
BUG: fix GAM for 1-dim exog_linear closes statsmodels#6506
BUG: fix GAM for 1-dim exog_linear closes statsmodels#6506