class_docstr: LightGBM Model
class_docstr_tok: ["LightGBM","Model"]
docstr: The motivation of current version is to make validation optional
  - train segment is necessary;
docstr_tok: ["The","motivation","of","current","version","is","to","make","validation","optional","-","train","segment","is","necessary",";"]
code: def _prepare_data(
      self, dataset: DatasetH, reweighter=None
  ) -> List[Tuple[lgb.Dataset, str]]:
      """
      The motivation of current version is to make validation optional
      - train segment is necessary;
      """
      ds_l = []
      assert "train" in dataset.segments
      for key in ["train", "valid"]:
          if key in dataset.segments:
              df = dataset.prepare(
                  key,
                  col_set=["feature", "label"],
                  data_key=DataHandlerLP.DK_L,
              )
              if df.empty:
                  raise ValueError(
                      "Empty data from dataset, please check your dataset config."
                  )
              x, y = df["feature"], df["label"]
  
              # Lightgbm need 1D array as its label
              if y.values.ndim == 2 and y.values.shape[1] == 1:
                  y = np.squeeze(y.values)
              else:
                  raise ValueError(
                      "LightGBM doesn't support multi-label training"
                  )
  
              if reweighter is None:
                  w = None
              elif isinstance(reweighter, Reweighter):
                  w = reweighter.reweight(df)
              else:
                  raise ValueError("Unsupported reweighter type.")
              ds_l.append(
                  (lgb.Dataset(x.values, label=y, weight=w), key)
              )
      return ds_l
  
file_path: qlib/qlib/contrib/model/gbdt.py
imports: import numpy
  import pandas
  import lightgbm
  from typing import List, Text, Tuple, Union
  from ...model.base import ModelFT
  from ...data.dataset import DatasetH
  from ...data.dataset.handler import DataHandlerLP
  from ...model.interpret.base import LightGBMFInt
  from ...data.dataset.weight import Reweighter
  from qlib.workflow import R
label_desc: Use image node_id 2 for calling the LGBModel obj's underlying member method code with example usage: obj._prepare_data(dataset, reweighter) and returns: ds_l