class_docstr: Generalized Additive Models (GAM)
  
  This inherits from `GLM`.
  
  Warning: Not all inherited methods might take correctly account of the
  penalization. Not all options including offset and exposure have been
  verified yet.
  
  Parameters
  ----------
  endog : array_like
      The response variable.
  exog : array_like or None
      This explanatory variables are treated as linear. The model in this
      case is a partial linear model.
  smoother : instance of additive smoother class
      Examples of smoother instances include Bsplines or CyclicCubicSplines.
  alpha : float or list of floats
      Penalization weights for smooth terms. The length of the list needs
      to be the same as the number of smooth terms in the ``smoother``.
  family : instance of GLM family
      See GLM.
  offset : None or array_like
      See GLM.
  exposure : None or array_like
      See GLM.
  missing : 'none'
      Missing value handling is not supported in this class.
  **kwargs
      Extra keywords are used in call to the super classes.
  
  Notes
  -----
  Status: experimental. This has full unit test coverage for the core
  results with Gaussian and Poisson (without offset and exposure). Other
  options and additional results might not be correctly supported yet.
  (Binomial with counts, i.e. with n_trials, is most likely wrong in pirls.
  User specified var or freq weights are most likely also not correct for
  all results.)
class_docstr_tok: ["Generalized","Additive","Models","(","GAM",")","This","inherits","from","`","GLM","`",".","Warning",":","Not","all","inherited","methods","might","take","correctly","account","of","the","penalization",".","Not","all","options","including","offset","and","exposure","have","been","verified","yet",".","Parameters","--","--","--","--","--","endog",":","array_like","The","response","variable",".","exog",":","array_like","or","None","This","explanatory","variables","are","treated","as","linear",".","The","model","in","this","case","is","a","partial","linear","model",".","smoother",":","instance","of","additive","smoother","class","Examples","of","smoother","instances","include","Bsplines","or","CyclicCubicSplines",".","alpha",":","float","or","list","of","floats","Penalization","weights","for","smooth","terms",".","The","length","of","the","list","needs","to","be","the","same","as","the","number","of","smooth","terms","in","the","``","smoother","``",".","family",":","instance","of","GLM","family","See","GLM",".","offset",":","None","or","array_like","See","GLM",".","exposure",":","None","or","array_like","See","GLM",".","missing",":","'none'","Missing","value","handling","is","not","supported","in","this","class",".","*","*","kwargs","Extra","keywords","are","used","in","call","to","the","super","classes",".","Notes","--","--","-","Status",":","experimental",".","This","has","full","unit","test","coverage","for","the","core","results","with","Gaussian","and","Poisson","(","without","offset","and","exposure",")",".","Other","options","and","additional","results","might","not","be","correctly","supported","yet",".","(","Binomial","with","counts",",","i.e",".","with","n_trials",",","is","most","likely","wrong","in","pirls",".","User","specified","var","or","freq","weights","are","most","likely","also","not","correct","for","all","results",".",")"]
docstr: 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)]``
docstr_tok: ["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",")","]","``"]
code: def select_penweight_kfold(
      self,
      alphas=None,
      cv_iterator=None,
      cost=None,
      k_folds=5,
      k_grid=11,
  ):
      """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)]``
      """
  
      if cost is None:
  
          def cost(x1, x2):
              return np.linalg.norm(x1 - x2) / len(x1)
  
      if alphas is None:
          alphas = [
              np.logspace(0, 7, k_grid) for _ in range(self.k_smooths)
          ]
  
      if cv_iterator is None:
          cv_iterator = KFold(k_folds=k_folds, shuffle=True)
  
      gam_cv = MultivariateGAMCVPath(
          smoother=self.smoother,
          alphas=alphas,
          gam=GLMGam,
          cost=cost,
          endog=self.endog,
          exog=self.exog_linear,
          cv_iterator=cv_iterator,
      )
      gam_cv_res = gam_cv.fit()
  
      return gam_cv_res.alpha_cv, gam_cv_res
  
imports: from collections.abc import Iterable
  import copy
  import numpy
  from scipy import optimize
  import pandas
  import statsmodels.base.wrapper
  from statsmodels.discrete.discrete_model import Logit
  from statsmodels.genmod.generalized_linear_model import GLM, GLMResults, GLMResultsWrapper, _check_convergence
  import statsmodels.regression.linear_model
  from statsmodels.tools.sm_exceptions import PerfectSeparationError, ValueWarning
  from statsmodels.tools.decorators import cache_readonly
  from statsmodels.tools.data import _is_using_pandas
  from statsmodels.tools.linalg import matrix_sqrt
  from statsmodels.base._penalized import PenalizedMixin
  from statsmodels.gam.gam_penalties import MultivariateGamPenalty
  from statsmodels.gam.gam_cross_validation.gam_cross_validation import MultivariateGAMCVPath
  from statsmodels.gam.gam_cross_validation.cross_validators import KFold
label_desc: Use image node_id 6 for calling the GLMGam obj's underlying member method code with example usage: obj.select_penweight_kfold(alphas, cv_iterator, cost, k_folds, k_grid) and returns: gam_cv_res,  gam_cv_res, unknown