microsoft/qlib · error · ValueError
LightGBM doesn't support multi-label training
Error message
LightGBM doesn't support multi-label training
What it means
Thrown by HFMLGBModel._prepare_data when the label block is not exactly one column. The model converts the single label into a per-timestamp alpha and then a binary label_c (0/1 by sign) for the LightGBM classifier; multiple label columns leave no unambiguous target, and LightGBM needs a 1D label anyway.
Source
Thrown at qlib/contrib/model/highfreq_gdbt_model.py:110
# Convert label into alpha
df_train.loc[:, ("label", l_name)] = (
df_train.loc[:, ("label", l_name)]
- df_train.loc[:, ("label", l_name)].groupby(level=0, group_keys=False).mean()
)
df_valid.loc[:, ("label", l_name)] = (
df_valid.loc[:, ("label", l_name)]
- df_valid.loc[:, ("label", l_name)].groupby(level=0, group_keys=False).mean()
)
def mapping_fn(x):
return 0 if x < 0 else 1
df_train["label_c"] = df_train["label"][l_name].apply(mapping_fn)
df_valid["label_c"] = df_valid["label"][l_name].apply(mapping_fn)
x_train, y_train = df_train["feature"], df_train["label_c"].values
x_valid, y_valid = df_valid["feature"], df_valid["label_c"].values
else:
raise ValueError("LightGBM doesn't support multi-label training")
dtrain = lgb.Dataset(x_train, label=y_train)
dvalid = lgb.Dataset(x_valid, label=y_valid)
return dtrain, dvalid
def fit(
self,
dataset: DatasetH,
num_boost_round=1000,
early_stopping_rounds=50,
verbose_eval=20,
evals_result=None,
):
if evals_result is None:
evals_result = dict()
dtrain, dvalid = self._prepare_data(dataset)
early_stopping_callback = lgb.early_stopping(early_stopping_rounds)
verbose_eval_callback = lgb.log_evaluation(period=verbose_eval)View on GitHub (pinned to 79633dd950)
Solutions
- Configure exactly one label expression in the data handler
- Move any extra targets into features or pick a multi-output-capable model
Example fix
# before label: ["Ref($close, -2)/Ref($close, -1) - 1", "$vwap/$close - 1"] # after label: ["Ref($close, -2)/Ref($close, -1) - 1"]
Defensive patterns
Strategy: validation
Validate before calling
y = dataset.prepare("train", col_set="label", data_key="learn")
assert y.values.ndim == 2 and y.values.shape[1] == 1, "HFMLGBModel needs a single label column to build the binary target" Prevention
- Single label expression in high-frequency handler configs
- The label is binarized internally (up/down by sign), so extra label columns are meaningless here anyway
When it happens
Trigger: Fitting HFMLGBModel with a handler label list containing more than one expression, so y_train.values.shape[1] != 1.
Common situations: Reusing a multi-label handler config from another model with the high-frequency workflow; adding auxiliary label columns for analysis.
Related errors
- LightGBM doesn't support multi-label training
- LightGBM doesn't support multi-label training
- Model hasn't been trained yet
- CatBoost doesn't support multi-label training
- Empty data from dataset, please check your dataset config.
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/6be0c4ad8ca75a7c.
Report an issue: GitHub.