Repository navigation
[FIX] Nomogram: Use softmax for multinomial logistic regression - #7331
Open
MohammadHijjawi97 wants to merge 2 commits into
Open
MohammadHijjawi97 wants to merge 2 commits into
MohammadHijjawi97 wants to merge 2 commits into
Conversation
Logistic regression with more than two classes is multinomial and computes probabilities with softmax, but the nomogram showed per-class sigmoids (optionally normalized by their sum), which did not match the model's predictions. Compute probabilities (and the probability scale) with softmax over the totals of all class values, extend the total ruler to cover all reachable totals and hide the (now redundant) normalization checkbox for logistic regression. Fixes biolab#7326
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #7331 +/- ##
==========================================
+ Coverage 88.99% 89.02% +0.03%
==========================================
Files 337 337
Lines 74598 74614 +16
==========================================
+ Hits 66387 66427 +40
+ Misses 8211 8187 -24 🚀 New features to boost your workflow:
|
VesnaT
reviewed
Oct 9, 2026
VesnaT
left a comment
Contributor
There was a problem hiding this comment.
Thank you for the fix. It looks promising, but I found a few issues:
- With the points scale and some features hidden, the nomogram shows probabilities that don't match the model.
- With the points scale and some features hidden, the nomogram shows probabilities that don't match the model.
- When the target class has zero coefficients, (use L1) the nomogram shows wrong probabilities.
- When there are two classes with zero coefficients, the nomogram crashes.
…fficients The totals of other class values were reconstructed from the target's marker values through the ratios of coefficients and rescaled with a scale computed from all features instead of the shown ones. This gave wrong probabilities when the most important features were hidden, when coefficients of the target were zero (L1), and crashed when all its coefficients were zero. For logistic regression, keep the points of all class values at the markers and compute the softmax from them. Update them when a marker is dragged, so the probabilities follow the dragged markers and the markers are kept when the target class or the scale changes. Normalized probabilities (naive Bayes) now use the scale of the shown features.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Fixes #7326
Description of changes
Logistic regression on data with more than two classes is multinomial and computes its probabilities with softmax. The nomogram instead turned the target class's points into a probability with a per-class sigmoid, optionally normalized by the sum of the sigmoids, so the displayed probabilities did not match the model's predictions. For example, for iris[53] the model gives 2/94/5 % but the nomogram showed 15/92/34 %.
__get_totals_for_class_valueshelper.Tests:
test_probabilities_lr_multiclass: for several iris instances, both scales and every target class, the displayed probability equalscls(inst, cls.Probs), and the ruler covers the total.test_nomogram_lr_multiclassfrom[18, 56, 78], which summed to 152 %, to[4, 25, 70]. These are the model'spredict_probaat the marker position (0.0439 / 0.2533 / 0.7027).I also compared the nomogram with the model across instances of iris, zoo and heart_disease, with both scales and with 5 or all features. After the fix they agree to within 1 %.
Note: I tested on Windows against the 3.40.0 wheel. There, a few existing nomogram tests fail the same way before and after this change, because the hidden widget is narrow and the ruler collapses. With the widget sized to 1400x900 they pass. I couldn't check the new expected values in
test_nomogram_lr_multiclasswith CI's default widget size, so please check that one in CI.Includes