Search code examples
pythonstatsmodelsgam

Python statsmodels GAM: How to choose penalties?


I am wondering how to choose the penalties resp. the alpha using GAM with statsmodels. The documentation of statsmodels gam states:

The alpha above are from the unit tests against the R mgcv package.

So does that mean there is no python/statsmodels way to choose the penalties/alpha? If I need R mgcv for that, then I'd use R right away, but I'd like to implement my model in python.


Solution

  • GAM in statsmodels has two methods to select the penalization weights in the Model class

    The first uses information criteria like aic, bic or gcv
    https://www.statsmodels.org/dev/generated/statsmodels.gam.generalized_additive_model.GLMGam.select_penweight.html

    The second uses k-fold cross validation
    https://www.statsmodels.org/dev/generated/statsmodels.gam.generalized_additive_model.GLMGam.select_penweight_kfold.html

    The usage is shown at the end of the documentation example https://www.statsmodels.org/dev/gam.html