parameters: (
          self,
          X,
          y,
          sample_weight=None,
          init_score=None,
          group=None,
          eval_set=None,
          eval_names=None,
          eval_sample_weight=None,
          eval_class_weight=None,
          eval_init_score=None,
          eval_group=None,
          eval_metric=None,
          feature_name='auto',
          categorical_feature='auto',
          callbacks=None,
          init_model=None
      )
return_statement: return self
docstring: Docstring is set after definition, using a template.
docstring_summary: Docstring is set after definition, using a template.
docstring_tokens: Docstring is set after definition using a template .
function: def fit(
          self,
          X,
          y,
          sample_weight=None,
          init_score=None,
          group=None,
          eval_set=None,
          eval_names=None,
          eval_sample_weight=None,
          eval_class_weight=None,
          eval_init_score=None,
          eval_group=None,
          eval_metric=None,
          feature_name='auto',
          categorical_feature='auto',
          callbacks=None,
          init_model=None
      ):
          """Docstring is set after definition, using a template."""
          params = self._process_params(stage="fit")
  
          # Do not modify original args in fit function
          # Refer to https://github.com/microsoft/LightGBM/pull/2619
          eval_metric_list = copy.deepcopy(eval_metric)
          if not isinstance(eval_metric_list, list):
              eval_metric_list = [eval_metric_list]
  
          # Separate built-in from callable evaluation metrics
          eval_metrics_callable = [_EvalFunctionWrapper(f) for f in eval_metric_list if callable(f)]
          eval_metrics_builtin = [m for m in eval_metric_list if isinstance(m, str)]
  
          # concatenate metric from params (or default if not provided in params) and eval_metric
          params['metric'] = [params['metric']] if isinstance(params['metric'], (str, type(None))) else params['metric']
          params['metric'] = [e for e in eval_metrics_builtin if e not in params['metric']] + params['metric']
          params['metric'] = [metric for metric in params['metric'] if metric is not None]
  
          if not isinstance(X, (pd_DataFrame, dt_DataTable)):
              _X, _y = _LGBMCheckXY(X, y, accept_sparse=True, force_all_finite=False, ensure_min_samples=2)
              if sample_weight is not None:
                  sample_weight = _LGBMCheckSampleWeight(sample_weight, _X)
          else:
              _X, _y = X, y
  
          if self._class_weight is None:
              self._class_weight = self.class_weight
          if self._class_weight is not None:
              class_sample_weight = _LGBMComputeSampleWeight(self._class_weight, y)
              if sample_weight is None or len(sample_weight) == 0:
                  sample_weight = class_sample_weight
              else:
                  sample_weight = np.multiply(sample_weight, class_sample_weight)
  
          self._n_features = _X.shape[1]
          # copy for consistency
          self._n_features_in = self._n_features
  
          def _construct_dataset(X, y, sample_weight, init_score, group, params,
                                 categorical_feature='auto'):
              return Dataset(X, label=y, weight=sample_weight, group=group,
                             init_score=init_score, params=params,
                             categorical_feature=categorical_feature)
  
          train_set = _construct_dataset(_X, _y, sample_weight, init_score, group, params,
                                         categorical_feature=categorical_feature)
  
          valid_sets = []
          if eval_set is not None:
  
              def _get_meta_data(collection, name, i):
                  if collection is None:
                      return None
                  elif isinstance(collection, list):
                      return collection[i] if len(collection) > i else None
                  elif isinstance(collection, dict):
                      return collection.get(i, None)
                  else:
                      raise TypeError(f"{name} should be dict or list")
  
              if isinstance(eval_set, tuple):
                  eval_set = [eval_set]
              for i, valid_data in enumerate(eval_set):
                  # reduce cost for prediction training data
                  if valid_data[0] is X and valid_data[1] is y:
                      valid_set = train_set
                  else:
                      valid_weight = _get_meta_data(eval_sample_weight, 'eval_sample_weight', i)
                      valid_class_weight = _get_meta_data(eval_class_weight, 'eval_class_weight', i)
                      if valid_class_weight is not None:
                          if isinstance(valid_class_weight, dict) and self._class_map is not None:
                              valid_class_weight = {self._class_map[k]: v for k, v in valid_class_weight.items()}
                          valid_class_sample_weight = _LGBMComputeSampleWeight(valid_class_weight, valid_data[1])
                          if valid_weight is None or len(valid_weight) == 0:
                              valid_weight = valid_class_sample_weight
                          else:
                              valid_weight = np.multiply(valid_weight, valid_class_sample_weight)
                      valid_init_score = _get_meta_data(eval_init_score, 'eval_init_score', i)
                      valid_group = _get_meta_data(eval_group, 'eval_group', i)
                      valid_set = _construct_dataset(valid_data[0], valid_data[1],
                                                     valid_weight, valid_init_score, valid_group, params)
                  valid_sets.append(valid_set)
  
          if isinstance(init_model, LGBMModel):
              init_model = init_model.booster_
  
          if callbacks is None:
              callbacks = []
          else:
              callbacks = copy.copy(callbacks)  # don't use deepcopy here to allow non-serializable objects
  
          evals_result = {}
          callbacks.append(record_evaluation(evals_result))
  
          self._Booster = train(
              params=params,
              train_set=train_set,
              num_boost_round=self.n_estimators,
              valid_sets=valid_sets,
              valid_names=eval_names,
              fobj=self._fobj,
              feval=eval_metrics_callable,
              init_model=init_model,
              feature_name=feature_name,
              callbacks=callbacks
          )
  
          self._evals_result = evals_result
          self._best_iteration = self._Booster.best_iteration
          self._best_score = self._Booster.best_score
  
          self.fitted_ = True
  
          # free dataset
          self._Booster.free_dataset()
          del train_set, valid_sets
          return self
function_tokens: def fit ( self , X , y , sample_weight = None , init_score = None , group = None , eval_set = None , eval_names = None , eval_sample_weight = None , eval_class_weight = None , eval_init_score = None , eval_group = None , eval_metric = None , feature_name = 'auto' , categorical_feature = 'auto' , callbacks = None , init_model = None ) : params = self . _process_params ( stage = "fit" ) # Do not modify original args in fit function # Refer to https://github.com/microsoft/LightGBM/pull/2619 eval_metric_list = copy . deepcopy ( eval_metric ) if not isinstance ( eval_metric_list , list ) : eval_metric_list = [ eval_metric_list ] # Separate built-in from callable evaluation metrics eval_metrics_callable = [ _EvalFunctionWrapper ( f ) for f in eval_metric_list if callable ( f ) ] eval_metrics_builtin = [ m for m in eval_metric_list if isinstance ( m , str ) ] # concatenate metric from params (or default if not provided in params) and eval_metric params [ 'metric' ] = [ params [ 'metric' ] ] if isinstance ( params [ 'metric' ] , ( str , type ( None ) ) ) else params [ 'metric' ] params [ 'metric' ] = [ e for e in eval_metrics_builtin if e not in params [ 'metric' ] ] + params [ 'metric' ] params [ 'metric' ] = [ metric for metric in params [ 'metric' ] if metric is not None ] if not isinstance ( X , ( pd_DataFrame , dt_DataTable ) ) : _X , _y = _LGBMCheckXY ( X , y , accept_sparse = True , force_all_finite = False , ensure_min_samples = 2 ) if sample_weight is not None : sample_weight = _LGBMCheckSampleWeight ( sample_weight , _X ) else : _X , _y = X , y if self . _class_weight is None : self . _class_weight = self . class_weight if self . _class_weight is not None : class_sample_weight = _LGBMComputeSampleWeight ( self . _class_weight , y ) if sample_weight is None or len ( sample_weight ) == 0 : sample_weight = class_sample_weight else : sample_weight = np . multiply ( sample_weight , class_sample_weight ) self . _n_features = _X . shape [ 1 ] # copy for consistency self . _n_features_in = self . _n_features def _construct_dataset ( X , y , sample_weight , init_score , group , params , categorical_feature = 'auto' ) : return Dataset ( X , label = y , weight = sample_weight , group = group , init_score = init_score , params = params , categorical_feature = categorical_feature ) train_set = _construct_dataset ( _X , _y , sample_weight , init_score , group , params , categorical_feature = categorical_feature ) valid_sets = [ ] if eval_set is not None : def _get_meta_data ( collection , name , i ) : if collection is None : return None elif isinstance ( collection , list ) : return collection [ i ] if len ( collection ) > i else None elif isinstance ( collection , dict ) : return collection . get ( i , None ) else : raise TypeError ( f"{name} should be dict or list" ) if isinstance ( eval_set , tuple ) : eval_set = [ eval_set ] for i , valid_data in enumerate ( eval_set ) : # reduce cost for prediction training data if valid_data [ 0 ] is X and valid_data [ 1 ] is y : valid_set = train_set else : valid_weight = _get_meta_data ( eval_sample_weight , 'eval_sample_weight' , i ) valid_class_weight = _get_meta_data ( eval_class_weight , 'eval_class_weight' , i ) if valid_class_weight is not None : if isinstance ( valid_class_weight , dict ) and self . _class_map is not None : valid_class_weight = { self . _class_map [ k ] : v for k , v in valid_class_weight . items ( ) } valid_class_sample_weight = _LGBMComputeSampleWeight ( valid_class_weight , valid_data [ 1 ] ) if valid_weight is None or len ( valid_weight ) == 0 : valid_weight = valid_class_sample_weight else : valid_weight = np . multiply ( valid_weight , valid_class_sample_weight ) valid_init_score = _get_meta_data ( eval_init_score , 'eval_init_score' , i ) valid_group = _get_meta_data ( eval_group , 'eval_group' , i ) valid_set = _construct_dataset ( valid_data [ 0 ] , valid_data [ 1 ] , valid_weight , valid_init_score , valid_group , params ) valid_sets . append ( valid_set ) if isinstance ( init_model , LGBMModel ) : init_model = init_model . booster_ if callbacks is None : callbacks = [ ] else : callbacks = copy . copy ( callbacks ) # don't use deepcopy here to allow non-serializable objects evals_result = { } callbacks . append ( record_evaluation ( evals_result ) ) self . _Booster = train ( params = params , train_set = train_set , num_boost_round = self . n_estimators , valid_sets = valid_sets , valid_names = eval_names , fobj = self . _fobj , feval = eval_metrics_callable , init_model = init_model , feature_name = feature_name , callbacks = callbacks ) self . _evals_result = evals_result self . _best_iteration = self . _Booster . best_iteration self . _best_score = self . _Booster . best_score self . fitted_ = True # free dataset self . _Booster . free_dataset ( ) del train_set , valid_sets return self