Skip to content

Kmeans fit sideeffect: sample_weight is parameter is modified #17203

Closed

Description

@mseehafer

Describe the bug

The array passed in to fit() or fit_predict for the argument sample weight is modified (rescaled) in the method with side effects outside the call.

Steps/Code to Reproduce

Example:

import numpy as np
from sklearn.cluster import KMeans

X = np.array([[1], [2], [4]])
sample_weights = np.array([0.5, 0.2, 0.3])
kmeans = KMeans(n_clusters=2, random_state=4321)
y_kmeans = kmeans.fit_predict(X, sample_weight=sample_weights)
print(sample_weights)

Activity

  1. jeremiedbb commented on May 13, 2020

    @jeremiedbb
    Member

    Thanks for the report. Not the expected behavior indeed. #17204 fixes it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions