statsmodels.gam.generalized_additive_model.GLMGam.select_penweight_kfold#

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

Find alphas by k-fold cross-validation

Warning: This estimates k_folds models for each point in the

grid of alphas.

Parameters:
alphasNone or list of arrays

Grid of alpha values to search over, one array per smooth term. If None, a default grid is constructed, see Notes.

cv_iteratorinstance

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

costfunction

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_foldsint

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

k_gridint

number of points in the default grid of alpha values for each smooth term. This is ignored if alphas is not None.

rng{None, int, array_like[int], numpy.random.Generator, numpy.random.RandomState}, optional

If rng is None, a new Generator is created using fresh entropy from the operating system. If rng is an int or array of ints, a new Generator is created, seeded with rng. If rng is already a Generator or RandomState instance, that instance is used.

Returns:
alpha_cvlist of float

Best alpha in grid according to cross-validation

res_cvinstance 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)]