Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Loosened to dist <= stop_thresh to converge in on 1D constant data #28951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions 3 doc/whats_new/v1.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ Changelog
:mod:`sklearn.cluster`
......................

- |Fix| The :class:`cluster.MeanShift` class now properly converges for constant data.
:pr:`28951` by :user:`Akihiro Kuno <akikuno>`.

- |FIX| Create copy of precomputed sparse matrix within the `fit` method of
:class:`~cluster.OPTICS` to avoid in-place modification of the sparse matrix.
:pr:`28491` by :user:`Thanh Lam Dang <lamdang2k>`.
Expand Down
2 changes: 1 addition & 1 deletion 2 sklearn/cluster/_mean_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _mean_shift_single_seed(my_mean, X, nbrs, max_iter):
my_mean = np.mean(points_within, axis=0)
# If converged or at max_iter, adds the cluster
if (
np.linalg.norm(my_mean - my_old_mean) < stop_thresh
np.linalg.norm(my_mean - my_old_mean) <= stop_thresh
or completed_iterations == max_iter
):
break
Expand Down
9 changes: 9 additions & 0 deletions 9 sklearn/cluster/tests/test_mean_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
)


def test_convergence_of_1d_constant_data():
# Test convergence using 1D constant data
# Non-regression test for:
# https://github.com/scikit-learn/scikit-learn/issues/28926
model = MeanShift()
n_iter = model.fit(np.ones(10).reshape(-1, 1)).n_iter_
assert n_iter < model.max_iter


def test_estimate_bandwidth():
# Test estimate_bandwidth
bandwidth = estimate_bandwidth(X, n_samples=200)
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.