class_docstr: The ClassicalTextExplainer for returning explanations for n-gram
  bag-of-words models using sklearn's classifier API.
  Also serves as extensible wrapper with components built to support addition
  of fresh explainers using certain parts of this class.
class_docstr_tok: ["The","ClassicalTextExplainer","for","returning","explanations","for","n-gram","bag-of-words","models","using","sklearn","'s","classifier","API",".","Also","serves","as","extensible","wrapper","with","components","built","to","support","addition","of","fresh","explainers","using","certain","parts","of","this","class","."]
docstr: Trains the model with training data and labels.
      Includes:
      * Encoding X_str into vector form.
      *Note*: y_train is assumed to be encoded into sklearn compatible format.
      (use sklearn's label encoder for this purpose externally)
      * Training the model.
      * Grid search over parameter range.
      * Returns best model and corresponding hyper parameters.
  :param X_str: Dataset of strings to train on.
  :type X_str: array_like (array of strings, ndarray, pandas dataframe)
  :param y_train: Labels in encoded vector form directly sent to model.fit().
  :type y_train: array_like
  :return: List of length 2 . The elements are:
      * An sklearn pipeline object containing trained encoder and trained model.
      * Dict containing mapping from features to the best hyperparameters.
  :rtype: list
docstr_tok: ["Trains","the","model","with","training","data","and","labels",".","Includes",":","*","Encoding","X_str","into","vector","form",".","*","Note","*",":","y_train","is","assumed","to","be","encoded","into","sklearn","compatible","format",".","(","use","sklearn","'s","label","encoder","for","this","purpose","externally",")","*","Training","the","model",".","*","Grid","search","over","parameter","range",".","*","Returns","best","model","and","corresponding","hyper","parameters",".",":","param","X_str",":","Dataset","of","strings","to","train","on",".",":","type","X_str",":","array_like","(","array","of","strings",",","ndarray",",","pandas","dataframe",")",":","param","y_train",":","Labels","in","encoded","vector","form","directly","sent","to","model.fit","(",")",".",":","type","y_train",":","array_like",":","return",":","List","of","length","2",".","The","elements","are",":","*","An","sklearn","pipeline","object","containing","trained","encoder","and","trained","model",".","*","Dict","containing","mapping","from","features","to","the","best","hyperparameters",".",":","rtype",":","list"]
code: def fit(self, X_str, y_train):
      """Trains the model with training data and labels.
          Includes:
          * Encoding X_str into vector form.
          *Note*: y_train is assumed to be encoded into sklearn compatible format.
          (use sklearn's label encoder for this purpose externally)
          * Training the model.
          * Grid search over parameter range.
          * Returns best model and corresponding hyper parameters.
      :param X_str: Dataset of strings to train on.
      :type X_str: array_like (array of strings, ndarray, pandas dataframe)
      :param y_train: Labels in encoded vector form directly sent to model.fit().
      :type y_train: array_like
      :return: List of length 2 . The elements are:
          * An sklearn pipeline object containing trained encoder and trained model.
          * Dict containing mapping from features to the best hyperparameters.
      :rtype: list
      """
      X_train = self._encode(X_str)
      if self.is_trained is False:
          if self.model is None:
              self.model = LogisticRegression()
              # Hyperparameters were chosen through hyperparamter optimization on MNLI
              self.hyperparam_range = [ExplainerParams.HYPERPARAM_RANGE]
              self.hyperparam_range[0]["tol"] = [self.tol]
          classifier_CV = GridSearchCV(
              self.model,
              self.hyperparam_range,
              cv=3,
              scoring="accuracy",
              n_jobs=self.n_jobs,
          )
          classifier_CV.fit(X_train, y_train)
          # set model as the best estimator from grid search results
          self.model = classifier_CV.best_estimator_
          best_params = classifier_CV.best_params_
      else:
          best_params = self.model.get_params()
  
      text_model = Pipeline(
          steps=[
              ("preprocessor", Encoder(self)),
              ("classifier", self.model),
          ]
      )
      return [text_model, best_params]
  
file_path: interpret-text/python/interpret_text/experimental/classical.py
imports: import numpy
  from sklearn.model_selection import GridSearchCV
  from sklearn.linear_model import LogisticRegression
  from sklearn.pipeline import Pipeline
  from interpret_text.experimental.common.base_explainer import _validate_X
  from interpret_text.experimental.common.utils_classical import BOWEncoder
  from interpret_text.experimental.common.constants import ExplainerParams
  from interpret_text.experimental.explanation import _create_local_explanation
label_desc: Use image node_id 4 for calling the ClassicalTextExplainer obj's underlying member method code with example usage: obj.fit(X_str, y_train) and returns: list