onnxruntime
db641d65 - Fix regression in RandomForestClassifier binary classification predictions (#28685)

Commit
24 days ago
Fix regression in RandomForestClassifier binary classification predictions (#28685) ### Description Restores the `weights_are_all_positive_` flag in `TreeEnsembleClassifier` that was removed in PR #27552. This flag controls how binary classification scores are converted to two-class probabilities in `_set_score_binary`: - **All-positive weights** (RandomForest, where leaf weights are probabilities ∈ [0,1]): threshold `> 0.5`, complement via `1 - score` (`write_additional_scores` = 0/1) - **Mixed weights** (gradient boosted trees, where weights can be negative): threshold `> 0`, complement via `-score` (`write_additional_scores` = 2/3) Without this distinction, RandomForest models produce negative "probabilities" and incorrect labels when the score falls in (0, 0.5). The LOGISTIC post_transform path (the #27533 fix) is unaffected because `write_scores` applies `sigmoid(score)` / `sigmoid(-score)` identically for both cases 0/1 and 2/3. ### Motivation and Context PR #27552 fixed #27533 (LOGISTIC transform with negative weights) but inadvertently broke all binary `TreeEnsembleClassifier` models with non-negative weights and non-LOGISTIC post_transform — notably sklearn `RandomForestClassifier` conversions via skl2onnx. ```python # Reproducer: predictions no longer match sklearn, probabilities go negative sess = ort.InferenceSession(onnx_model.SerializeToString()) onnx_labels, onnx_probs = sess.run(None, {"float_input": X_test}) # onnx_probs contains negative values, row sums ≠ 1.0 ``` --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Tianlei Wu <tlwu@microsoft.com>
Author
Parents
Loading