Skip to content

Fix bugs in Scholar.Metrics.Regression - #377

Merged
josevalim merged 1 commit into
elixir-nx:mainfrom
bardrop-oss:fix-regression-metrics-axes
Nov 23, 2026
Merged

josevalim merged 1 commit into
elixir-nx:mainfrom
bardrop-oss:fix-regression-metrics-axes

Conversation

@bardrop

@bardrop bardrop commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Closes #376.

  • r2_score with :axes. The total sum of squares used the mean of the whole tensor. It now uses the mean over :axes, so axes: [0] matches scikit-learn's multioutput="raw_values". The axes: [0] doctest expected the old value and is updated.
  • explained_variance_score on rank 2 tensors. The numerator was divided by the size of axis 0 whatever :axes was, which gave wrong scores without :axes. With axes: [1] it raised. Both sides are now means over the same axes.
  • mean_poisson_deviance with zeros in y_true. 0 * log(0) gave NaN. That term is now 0, as with scikit-learn's xlogy. mean_tweedie_deviance and d2_tweedie_score with power 1 had the same problem.

Checked against scikit-learn on 300 random inputs (2 to 11 samples, 1 to 4 outputs, Poisson counts) in f64. Before, r2_score with axes: [0] differed on 232, explained_variance_score without :axes on 232, and mean_poisson_deviance on 244. Now all agree to 1e-9.

The four new tests fail on main and pass with this change.

@josevalim
josevalim merged commit 3b82b0a into elixir-nx:main Nov 23, 2026
2 checks passed
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.

r2_score, explained_variance_score and mean_poisson_deviance differ from scikit-learn

2 participants