class_docstr: Linear Model
  
  Solve one of the following regression problems:
      - `ols`: min_w |y - Xw|^2_2
      - `nnls`: min_w |y - Xw|^2_2, s.t. w >= 0
      - `ridge`: min_w |y - Xw|^2_2 + lpha*|w|^2_2
      - `lasso`: min_w |y - Xw|^2_2 + lpha*|w|_1
  where `w` is the regression coefficient.
class_docstr_tok: ["Linear","Model","Solve","one","of","the","following","regression","problems",":","-","`","ols","`",":","min_w","|y","-","Xw|^2_2","-","`","nnls","`",":","min_w","|y","-","Xw|^2_2",",","s.t",".","w",">","=","0","-","`","ridge","`",":","min_w","|y","-","Xw|^2_2","+","\u0007lpha","*","|w|^2_2","-","`","lasso","`",":","min_w","|y","-","Xw|^2_2","+","\u0007lpha","*","|w|_1","where","`","w","`","is","the","regression","coefficient","."]
code: def fit(self, dataset: DatasetH, reweighter: Reweighter = None):
      df_train = dataset.prepare(
          "train",
          col_set=["feature", "label"],
          data_key=DataHandlerLP.DK_L,
      )
      if self.include_valid:
          try:
              df_valid = dataset.prepare(
                  "valid",
                  col_set=["feature", "label"],
                  data_key=DataHandlerLP.DK_L,
              )
              df_train = pd.concat([df_train, df_valid])
          except KeyError:
              get_module_logger("LinearModel").info(
                  "include_valid=True, but valid does not exist"
              )
      if df_train.empty:
          raise ValueError(
              "Empty data from dataset, please check your dataset config."
          )
      if reweighter is not None:
          w: pd.Series = reweighter.reweight(df_train)
          w = w.values
      else:
          w = None
      X, y = df_train["feature"].values, np.squeeze(
          df_train["label"].values
      )
  
      if self.estimator in [self.OLS, self.RIDGE, self.LASSO]:
          self._fit(X, y, w)
      elif self.estimator == self.NNLS:
          self._fit_nnls(X, y, w)
      else:
          raise ValueError(f"unknown estimator `{self.estimator}`")
  
      return self
  
file_path: qlib/qlib/contrib/model/linear.py
imports: import numpy
  import pandas
  from typing import Text, Union
  from qlib.log import get_module_logger
  from qlib.data.dataset.weight import Reweighter
  from scipy.optimize import nnls
  from sklearn.linear_model import LinearRegression, Ridge, Lasso
  from ...model.base import Model
  from ...data.dataset import DatasetH
  from ...data.dataset.handler import DataHandlerLP
label_desc: Use image node_id 2 for calling the LinearModel obj's underlying member method code with example usage: obj.fit(dataset, reweighter) and returns: self