yobx.sklearn.imblearn.balanced_random_forest#

yobx.sklearn.imblearn.balanced_random_forest.sklearn_balanced_random_forest_classifier(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: BalancedRandomForestClassifier, X: str, name: str = 'balanced_random_forest_classifier') str | Tuple[str, str][source]#

Converts an imblearn.ensemble.BalancedRandomForestClassifier into ONNX.

BalancedRandomForestClassifier is a subclass of RandomForestClassifier that trains each tree on a balanced bootstrap sample (obtained by random under-sampling). At inference time the resampling step is inactive; the resulting forest has exactly the same structure as a regular RandomForestClassifier and is therefore converted using the same helpers.

When ai.onnx.ml opset 5 (or later) is active in the graph builder the unified TreeEnsemble operator is used; otherwise the legacy TreeEnsembleClassifier operator is emitted.

The forest is encoded as a single multi-tree ONNX node where each estimator’s leaf weights are divided by n_estimators so that the SUM aggregate (or NONE post-transform in the legacy path) yields the averaged class-probability vector used by predict_proba().

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

  • sts – shapes defined by scikit-learn

  • outputs – desired output names (label, probabilities)

  • estimator – a fitted BalancedRandomForestClassifier

  • X – input tensor name

  • name – prefix for node names added to the graph

Returns:

label tensor name, or tuple (label_result_name, proba_result_name)