Skip to content

FIX MinCovDet: no spurious "Determinant has increased" warning - #35531

Merged
OmarManzoor merged 5 commits into
scikit-learn:mainfrom
lorentzenchr:test_warnings_covariance
Nov 30, 2026
Merged

OmarManzoor merged 5 commits into
scikit-learn:mainfrom
lorentzenchr:test_warnings_covariance

Conversation

@lorentzenchr

@lorentzenchr lorentzenchr commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Reference Issues/PRs

Follow-up of #35476, towards a warning-free test suite (see #5685).

What does this implement/fix? Explain your changes.

With this PR,
pytest -W error -W "ignore::sklearn.exceptions.SkipTestWarning" sklearn/covariance
passes. It had 3 failures before.

Fix in MinCovDet

The C-step only checked convergence by comparing log-determinants. If the
support does not change between two steps, location and covariance are
mathematically identical, and any difference of the determinants is numerical
noise. For singular covariance matrices, this noise triggered

RuntimeWarning: Determinant has increased; this should not happen:
log(det) > log(previous_det) (-55.27 > -55.61). You may want to try with a
higher value of support_fraction

for example when n_samples == n_features, where the support contains all
samples, so that raising support_fraction cannot help.

An unchanged support is now treated as convergence. Example:

import numpy as np
from sklearn.covariance import MinCovDet

X = np.random.RandomState(42).randn(20, 20)
MinCovDet(random_state=42).fit(X)  # RuntimeWarning on main

AI usage disclosure

Claude Fable for

  • Code: Fix and test of the MinCovDet bug.
  • Analysis of test errors

I reviewed all changes.

…changed support

The c_step only checked convergence by comparing log-determinants. If the
support does not change between two steps, location and covariance are
mathematically identical, and a difference of the determinants is numerical
noise. This happens in particular for singular covariance matrices, e.g. when
n_samples == n_features and the support contains all samples.

Treat an unchanged support as convergence. Fitted results are unchanged.

Fix the remaining warnings in covariance tests

Co-Authored-By: Claude Fable 5.2 <[email protected]>

@OmarManzoor OmarManzoor 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.

LGTM. Thank you @lorentzenchr

@OmarManzoor
OmarManzoor enabled auto-merge (squash) November 30, 2026 08:20
@OmarManzoor

OmarManzoor commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

@lorentzenchr The CI is failing for a common test:

[gw3] linux -- Python 3.12.16 /home/runner/miniconda3/envs/testvenv/bin/python

model = LogisticRegression(l1_ratio=0.5, solver='saga', tol=1e-15)
with_sample_weight = False, global_random_seed = 0

FAILED linear_model/tests/test_common.py::test_balance_property[0-False-LogisticRegression] - assert np.float64(0.4462582590512244) == 0.44 ± 0.0044

This might be related to the saga with sample_weights PR that we recently merged https://github.com/scikit-learn/scikit-learn/pull/35417/changes#diff-a4a3b67b8880f9d5ed8632248be4a224287c41104a4e61d94350b4037b697618R66.

I think we might need to adjust the tolerance or the parameters, or remove the global_random_seed from the test_common.py::test_balance_property. Could you kindly check?

@OmarManzoor
OmarManzoor disabled auto-merge November 30, 2026 10:27
@OmarManzoor
OmarManzoor enabled auto-merge (squash) November 30, 2026 15:24
@OmarManzoor
OmarManzoor merged commit b16165a into scikit-learn:main Nov 30, 2026
37 checks passed
@github-actions github-actions Bot added the CI:Linter failure The linter CI is failing on this PR label Nov 30, 2026
@github-actions

Copy link
Copy Markdown

❌ Linting issues

There was an issue running the linter job. Please update with upstream/main (link) and push the changes. If you already have done that, please send an empty commit with git commit --allow-empty and push the changes to trigger the CI.

Generated for commit: 6aa44ee. Link to the linter CI: here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants