class_docstr: Implementation of Scikit-learn interface for xlearn models.
  
  :param model_type: one of 'lr', 'fm', 'ffm'
  :param task: 'binary' for classification or 'reg' for regression
  :param metric: 'acc', 'prec', 'recall', 'f1', 'auc' for classification,
      and 'mae', 'mape', 'rmsd (rmse)' for regression.
  :param log: location of log
  :param lr: learning rate
  :param k: latent factor for factorization
  :param reg_lambda: alias for lambda
  :param init: initial value
  :param fold: number of fold used in cross validation
  :param epoch: number of training epoch
  :param stop_window: window size for early stopping
  :param opt: optimizer option, one of 'sgd', 'adagrad', 'ftrl'
  :param nthread: number of threads (Deprecated, please use n_jobs)
  :param n_jobs: number of threads used to run xlearn.
  :param block_size: block size for on-disk training.
  :param alpha: alpha for FTRL
  :param beta: beta for FTRL
  :param lambda_1: lambda_1 for FTRL
  :param lambda_2: lambda_2 for FTRL
  :param kwargs: extra input arguments
class_docstr_tok: ["Implementation","of","Scikit-learn","interface","for","xlearn","models",".",":","param","model_type",":","one","of","'lr","'",",","'fm","'",",","'ffm'",":","param","task",":","'binary","'","for","classification","or","'reg","'","for","regression",":","param","metric",":","'acc","'",",","'prec","'",",","'recall","'",",","'f1","'",",","'auc","'","for","classification",",","and","'mae","'",",","'mape","'",",","'rmsd","(","rmse",")","'","for","regression",".",":","param","log",":","location","of","log",":","param","lr",":","learning","rate",":","param","k",":","latent","factor","for","factorization",":","param","reg_lambda",":","alias","for","lambda",":","param","init",":","initial","value",":","param","fold",":","number","of","fold","used","in","cross","validation",":","param","epoch",":","number","of","training","epoch",":","param","stop_window",":","window","size","for","early","stopping",":","param","opt",":","optimizer","option",",","one","of","'sgd","'",",","'adagrad","'",",","'ftrl'",":","param","nthread",":","number","of","threads","(","Deprecated",",","please","use","n_jobs",")",":","param","n_jobs",":","number","of","threads","used","to","run","xlearn",".",":","param","block_size",":","block","size","for","on-disk","training",".",":","param","alpha",":","alpha","for","FTRL",":","param","beta",":","beta","for","FTRL",":","param","lambda_1",":","lambda_1","for","FTRL",":","param","lambda_2",":","lambda_2","for","FTRL",":","param","kwargs",":","extra","input","arguments"]
docstr: Fit the XLearn model given feature matrix X and label y
  
  :param X: array-like or a string specifying file location
            Feature matrix
  :param y: array-like
            Label
  :param fields: array-like
            Fields for FFMModel. Default as None
  :param is_lock_free: is using lock-free training
  :param is_instance_norm: is using instance-wise normalization
  :param eval_set: a 2-element list representing (X_val, y_val) or a string specifying file location
  :param is_quiet: is training model quietly
docstr_tok: ["Fit","the","XLearn","model","given","feature","matrix","X","and","label","y",":","param","X",":","array-like","or","a","string","specifying","file","location","Feature","matrix",":","param","y",":","array-like","Label",":","param","fields",":","array-like","Fields","for","FFMModel",".","Default","as","None",":","param","is_lock_free",":","is","using","lock-free","training",":","param","is_instance_norm",":","is","using","instance-wise","normalization",":","param","eval_set",":","a","2-element","list","representing","(","X_val",",","y_val",")","or","a","string","specifying","file","location",":","param","is_quiet",":","is","training","model","quietly"]
code: def fit(
      self,
      X,
      y=None,
      fields=None,
      is_lock_free=True,
      is_instance_norm=True,
      eval_set=None,
      is_quiet=False,
  ):
      """Fit the XLearn model given feature matrix X and label y
  
      :param X: array-like or a string specifying file location
                Feature matrix
      :param y: array-like
                Label
      :param fields: array-like
                Fields for FFMModel. Default as None
      :param is_lock_free: is using lock-free training
      :param is_instance_norm: is using instance-wise normalization
      :param eval_set: a 2-element list representing (X_val, y_val) or a string specifying file location
      :param is_quiet: is training model quietly
      """
  
      if self.model_type == "fm":
          self._XLearnModel = create_fm()
      elif self.model_type == "lr":
          self._XLearnModel = create_linear()
      elif self.model_type == "ffm":
          self._XLearnModel = create_ffm()
      else:
          raise Exception("model_type must be fm, ffm or lr")
  
      if y is None:
          assert isinstance(X, str), (
              "X must be a string specifying training file location"
              " when only X specified"
          )
          self._XLearnModel.setTrain(X)
  
      else:
          X, y = check_X_y(
              X,
              y,
              accept_sparse=["csr"],
              y_numeric=True,
              multi_output=False,
          )
  
          if self.model_type == "ffm":
              assert (
                  fields is not None
              ), "Must specify fields in FFMModel"
              self.fields = fields
  
          # convert data into libsvm/libffm format for training
          train_set = DMatrix(X, y, self.fields)
          self._XLearnModel.setTrain(train_set)
  
      # TODO: find out what task need to set sigmoid
      if self.task == "binary":
          self._XLearnModel.setSigmoid()
  
      # set lock-free, is quiet training and instance-wise normalization
      if not is_lock_free:
          self._XLearnModel.disableLockFree()
  
      if is_quiet:
          self._XLearnModel.setQuiet()
  
      if not is_instance_norm:
          if self.model_type in ["fm", "ffm"]:
              self._XLearnModel.disableNorm()
          else:
              warnings.warn(
                  "Setting is_instance_norm to False is ignored. It only applies to fm or ffm."
              )
  
      params = self.get_xlearn_params()
  
      # check if validation set exists or not
      if eval_set is not None:
          if isinstance(eval_set, str):
              self._XLearnModel.setValidate(eval_set)
          else:
              if not (
                  isinstance(eval_set, list) and len(eval_set) == 2
              ):
                  raise Exception("eval_set must be a 2-element list")
  
              # extract validation data
              X_val, y_val = check_X_y(
                  eval_set[0],
                  eval_set[1],
                  accept_sparse=["csr"],
                  y_numeric=True,
                  multi_output=False,
              )
  
              validate_set = DMatrix(X_val, y_val, self.fields)
              self._XLearnModel.setValidate(validate_set)
  
      # set up files for storing weights
      self._XLearnModel.setTXTModel(self._temp_weight_file.name)
  
      # fit model
      self._XLearnModel.fit(params, self._temp_model_file.name)
  
      # acquire weights
      self._parse_weight(self._temp_weight_file.name)
  
imports: import os
  import shutil
  import tempfile
  import warnings
  import numpy
  from .xlearn import create_linear, create_fm, create_ffm
  from .data import DMatrix
  from sklearn.base import BaseEstimator
  from sklearn.utils import check_array, check_X_y
label_desc: Use image node_id 5 for calling the BaseXLearnModel obj's underlying member method code with example usage: obj.fit(X, y, fields, is_lock_free, is_instance_norm, eval_set, is_quiet) without return types