statsmodels.gam.generalized_additive_model.GLMGam.select_penweight_kfold

method

GLMGam.select_penweight_kfold(alphas=None, cv_iterator=None, cost=None, k_folds=5, k_grid=11)[source]

find alphas by k-fold cross-validation

Warning: This estimates k_folds models for each point in the
grid of alphas.
Parameters:

alphas : None or list of arrays

cv_iterator : instance

instance of a cross-validation iterator, by default this is a KFold instance

cost : function

default is mean squared error. The cost function to evaluate the prediction error for the left out sample. This should take two arrays as argument and return one float.

k_folds : int

number of folds if default Kfold iterator is used. This is ignored if cv_iterator is not None.

Returns:

alpha_cv : list of float

Best alpha in grid according to cross-validation

res_cv : instance of MultivariateGAMCVPath

The instance was used for cross-validation and holds the results

Notes

The default alphas are defined as alphas = [np.logspace(0, 7, k_grid) for _ in range(k_smooths)]