Skip to content

TypeError when using TimeSeriesKMeans from kmeans_plusplus requiring sample_weight argument #459

Open
@inega

Description

@inega

I am currently having an issue with TimeSeriesKMeans (tslearn version 0.5.3.2, sklearn version 1.3.0, running on Windows, python 3.11). I initially tried to use the function on my own dataset, but managed to reproduce the error with the first example in the documentation page:

from tslearn.clustering import TimeSeriesKMeans
from tslearn.generators import random_walks

X = random_walks(n_ts=50, sz=32, d=1)
km = TimeSeriesKMeans(n_clusters=3, metric="euclidean", max_iter=5, random_state=0).fit(X)

Traceback (most recent call last):

  Cell In[1], line 6
    km = TimeSeriesKMeans(n_clusters=3, metric="euclidean", max_iter=5, random_state=0).fit(X)

  File ~\.conda\envs\subsenv\Lib\site-packages\tslearn\clustering\kmeans.py:780 in fit
    self._fit_one_init(X_, x_squared_norms, rs)

  File ~\.conda\envs\subsenv\Lib\site-packages\tslearn\clustering\kmeans.py:629 in _fit_one_init
    self.cluster_centers_ = _kmeans_plusplus(

TypeError: _kmeans_plusplus() missing 1 required positional argument: 'sample_weight'

I think this might be a version issue? The kmeans_pluplus docs indicate that the sample_weight argument was introduced in version 1.3 of scikit-learn, which was just released. I guess downgrading to a previous version will make it go away, but I thought of reporting it anyway, since other people will start getting the same error at some point.

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