yobx.sklearn.lightgbm.lgbm_model#

ONNX converter for lightgbm.sklearn.LGBMModel.

LGBMModel is the configurable base class for all LightGBM sklearn-compatible estimators. Users instantiate it directly with a specific objective and call predict(), which returns:

  • Regression objectives (regression, regression_l1, huber, quantile, mape, …) — predicted values, shape [N].

  • Log-link regression (poisson, tweedie) — exp(margin), shape [N].

  • Binary classification (binary) — sigmoid probabilities in [0, 1], shape [N].

  • Multi-class classification (multiclass / softmax / …) — per-class probability matrix, shape [N, n_classes].

  • Ranking (lambdarank, rank_xendcg) — raw margin scores, shape [N].

The ONNX model produced by this converter follows the same logic and outputs a single tensor whose shape mirrors the ndim-normalised sklearn output: [N, 1] for scalar-per-sample objectives, or [N, n_classes] for multi-class objectives.

Both ai.onnx.ml legacy (opset ≤ 4) and modern (opset ≥ 5) tree encodings are supported, as well as float32 and float64 inputs.

yobx.sklearn.lightgbm.lgbm_model.sklearn_lgbm_model(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator, X: str, name: str = 'lgbm_model') str | List[str][source]#

Convert an lightgbm.sklearn.LGBMModel to ONNX.

The converter inspects the fitted booster’s objective string and dispatches to the appropriate conversion logic:

  • Regression (regression, regression_l1, huber, quantile, mape, …) — tree raw margin, optional exp transform for poisson / tweedie. Output shape [N, 1].

  • Binary classification (binary) — tree raw margin passed through sigmoid. Output shape [N, 1].

  • Multi-class classification (multiclass / softmax / …) — per-class raw margins passed through softmax. Output shape [N, n_classes].

  • Ranking (lambdarank, rank_xendcg) — raw margin scores, identity link. Output shape [N, 1].

Parameters:
  • g – the graph builder to add nodes to

  • sts – shapes dict (passed through, not used internally)

  • outputs – desired output names [predictions]

  • estimator – a fitted LGBMModel

  • X – input tensor name

  • name – prefix for node names added to the graph

Returns:

output tensor name

Raises:

NotImplementedError – if the model’s objective is not supported