original_docstring: 
          Fits a given algorithm, optionally performing hyperparameter tuning.
          
docstring: Fits a given algorithm, optionally performing hyperparameter tuning.
docstring_tokens: Fits a given algorithm optionally performing hyperparameter tuning .
code: def fit(self, features, labels):
  
          """
          Fits a given algorithm, optionally performing hyperparameter tuning.
          """
  
          try:
              start = datetime.now()
  
              if not self.optimize:
                  msg = "*** Training of model '{0}' started.".format(
                      self.clf.__class__.__name__
                  )
                  logging.info(msg)
  
                  if self.verbose:
                      print(msg)
                  
                  self.clf.fit(features, labels)
  
              else:
                  msg = "Starting gridsearch for {}...".format(
                      self.clf.estimator.__class__.__name__
                  )
                  logging.info(msg)
                  
                  if self.verbose:
                      print(msg)
                  
                  self.clf.fit(np.asarray(features), np.asarray(labels))
                  
                  if self.verbose:
                      print("Came up with params: {0}".format(self.clf.best_params_))
                      print("Achieved AUROC of {0}\n".format(self.clf.best_score_))
                  
                  """ clf now becomes the best estimator """
                  self.clf = self.clf.best_estimator_
  
              end = datetime.now()
              msg = "*** Training of classifier ready. Time elapsed: {}ms\n".format(
                  (end - start).microseconds / 1000
              )
              self.classes_ = self.clf.classes_
              
              logging.info(msg)
  
              if self.verbose:
                  print(msg)
  
              if self.crossval:
  
                  """ performing cross validation """
                  msg = "*** Performing cross validation of '{0}' classifier.".format(
                      self.clf.__class__.__name__
                  )
                  logging.info(msg)
                  if self.verbose:
                      print(msg)
                  """ keeps class proportion balanced across folds """
                  n_splits = self.n_splits or 10
                  print(f"Number of splits: {n_splits}")
                  skf = StratifiedKFold(n_splits=n_splits)
  
                  """ performs cross validation and stores the results in the respective variables """
                  n_jobs = self.n_jobs or 1
                  y_true, y_pred, y_probs = (
                      labels,
                      cross_val_predict(
                          self.clf,
                          features,
                          labels,
                          cv=skf,
                          n_jobs=n_jobs
                      ),
                      cross_val_predict(
                          self.clf,
                          features,
                          labels,
                          cv=skf,
                          method="predict_proba",
                          n_jobs=n_jobs
                      ),
                  )
  
                  """ performing cross validation """
                  msg = "Model cross-validation performed for {0}.".format(
                      self.clf.__class__.__name__
                  )
  
                  logging.info(msg)
                  if self.verbose:
                      print(msg)
  
                  """ if cross validation was required, return the discrimination metrics from crossvalidation """
                  """ note slicing of y_probs, we do it to get the prediction for label = 1"""
                  return get_discrimination_metrics(
                      y_true, y_pred, y_probs[:, 1]
                  )
  
          except Exception:
              print(traceback.format_exc())
              logging.error(traceback.format_exc())
  
          return None
code_tokens: def fit ( self , features , labels ) : try : start = datetime . now ( ) if not self . optimize : msg = "*** Training of model '{0}' started." . format ( self . clf . __class__ . __name__ ) logging . info ( msg ) if self . verbose : print ( msg ) self . clf . fit ( features , labels ) else : msg = "Starting gridsearch for {}..." . format ( self . clf . estimator . __class__ . __name__ ) logging . info ( msg ) if self . verbose : print ( msg ) self . clf . fit ( np . asarray ( features ) , np . asarray ( labels ) ) if self . verbose : print ( "Came up with params: {0}" . format ( self . clf . best_params_ ) ) print ( "Achieved AUROC of {0}\n" . format ( self . clf . best_score_ ) ) """ clf now becomes the best estimator """ self . clf = self . clf . best_estimator_ end = datetime . now ( ) msg = "*** Training of classifier ready. Time elapsed: {}ms\n" . format ( ( end - start ) . microseconds / 1000 ) self . classes_ = self . clf . classes_ logging . info ( msg ) if self . verbose : print ( msg ) if self . crossval : """ performing cross validation """ msg = "*** Performing cross validation of '{0}' classifier." . format ( self . clf . __class__ . __name__ ) logging . info ( msg ) if self . verbose : print ( msg ) """ keeps class proportion balanced across folds """ n_splits = self . n_splits or 10 print ( f"Number of splits: {n_splits}" ) skf = StratifiedKFold ( n_splits = n_splits ) """ performs cross validation and stores the results in the respective variables """ n_jobs = self . n_jobs or 1 y_true , y_pred , y_probs = ( labels , cross_val_predict ( self . clf , features , labels , cv = skf , n_jobs = n_jobs ) , cross_val_predict ( self . clf , features , labels , cv = skf , method = "predict_proba" , n_jobs = n_jobs ) , ) """ performing cross validation """ msg = "Model cross-validation performed for {0}." . format ( self . clf . __class__ . __name__ ) logging . info ( msg ) if self . verbose : print ( msg ) """ if cross validation was required, return the discrimination metrics from crossvalidation """ """ note slicing of y_probs, we do it to get the prediction for label = 1""" return get_discrimination_metrics ( y_true , y_pred , y_probs [ : , 1 ] ) except Exception : print ( traceback . format_exc ( ) ) logging . error ( traceback . format_exc ( ) ) return None
short_docstring: Fits a given algorithm, optionally performing hyperparameter tuning.
short_docstring_tokens: Fits a given algorithm optionally performing hyperparameter tuning .
comment: """
          Fits a given algorithm, optionally performing hyperparameter tuning.
          """$SEP$""" clf now becomes the best estimator """$SEP$""" performing cross validation """$SEP$""" keeps class proportion balanced across folds """$SEP$""" performs cross validation and stores the results in the respective variables """$SEP$""" performing cross validation """$SEP$""" if cross validation was required, return the discrimination metrics from crossvalidation """$SEP$""" note slicing of y_probs, we do it to get the prediction for label = 1"""