Skip to content

[FIX] Nomogram: Use softmax for multinomial logistic regression - #7331

Open
MohammadHijjawi97 wants to merge 2 commits into
biolab:masterfrom
MohammadHijjawi97:fix-nomogram-multiclass-lr
Open

MohammadHijjawi97 wants to merge 2 commits into
biolab:masterfrom
MohammadHijjawi97:fix-nomogram-multiclass-lr

Conversation

@MohammadHijjawi97

Copy link
Copy Markdown
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 %.

  • For multiclass logistic regression, the probabilities and the probability scale are now computed with softmax over the totals of all class values. This uses the existing __get_totals_for_class_values helper.
  • The total ruler now covers all reachable totals. Before, the dot was clipped for confident predictions (iris[0] showed 47 % while the model gives 98 %).
  • The "Normalize probabilities" checkbox is hidden for logistic regression, since softmax probabilities already sum to 1.
  • Naive Bayes and binary logistic regression are unchanged.

Tests:

  • Added test_probabilities_lr_multiclass: for several iris instances, both scales and every target class, the displayed probability equals cls(inst, cls.Probs), and the ruler covers the total.
  • Updated the expected values in test_nomogram_lr_multiclass from [18, 56, 78], which summed to 152 %, to [4, 25, 70]. These are the model's predict_proba at 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_multiclass with CI's default widget size, so please check that one in CI.

Includes
  • Code changes
  • Tests
  • Documentation

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
@CLAassistant

CLAassistant commented Sep 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Sep 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.02%. Comparing base (4d54417) to head (5a74093).
⚠️ Report is 1 commits behind head on master.

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@janezd janezd added this to the 3.41 milestone Oct 9, 2026

@VesnaT VesnaT left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix. It looks promising, but I found a few issues:

  1. With the points scale and some features hidden, the nomogram shows probabilities that don't match the model.
Image
  1. With the points scale and some features hidden, the nomogram shows probabilities that don't match the model.
Image
  1. When the target class has zero coefficients, (use L1) the nomogram shows wrong probabilities.
Image
  1. When there are two classes with zero coefficients, the nomogram crashes.
Image

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nomogram displays wrong probabilities for Logistic Regression on data with multiple class values

4 participants