Skip to content
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

[MRG] Fix empty clusters not correctly relocated #13486

Merged

Conversation

jeremiedbb
Copy link
Member

@jeremiedbb jeremiedbb commented Mar 21, 2019

When using sample weights in KMeans, empty clusters are not correctly relocated.

basically what was done is

# for some i
new_center = X[i]  # should be multiplied by the weight
...
new_center /= sample_weight[i]

the added test fails on master

Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -922,3 +923,15 @@ def test_iter_attribute():
estimator = KMeans(algorithm="elkan", max_iter=1)
estimator.fit(np.random.rand(10, 10))
assert estimator.n_iter_ == 1


def test_k_means_empty_cluster_relocated():
Copy link
Member

Choose a reason for hiding this comment

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

Add ref to this PR maybe?

@jeremiedbb jeremiedbb force-pushed the fix-kmeans-relocate-empty-clusters branch from f031479 to cca9378 Compare April 12, 2019 12:16
@jeremiedbb
Copy link
Member Author

@NicolasHug I think this PR can be merged

@@ -88,7 +88,11 @@ Support for Python 3.4 and below has been officially dropped.
- |API| The ``n_components_`` attribute in :class:`cluster.AgglomerativeClustering`
and :class:`cluster.FeatureAgglomeration` has been renamed to
``n_connected_components_``.

Copy link
Member

Choose a reason for hiding this comment

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

seems like there's a newline at the wrong place

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, merged master too quickly...

@NicolasHug NicolasHug merged commit e405505 into scikit-learn:master Apr 12, 2019
@NicolasHug
Copy link
Member

Thanks @jeremiedbb !

jeremiedbb added a commit to jeremiedbb/scikit-learn that referenced this pull request Apr 25, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
koenvandevelde pushed a commit to koenvandevelde/scikit-learn that referenced this pull request Jul 12, 2019
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.

None yet

3 participants