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

fda_kmeans.fit_predict(X) #599

Open
jack-pan-ai opened this issue Feb 25, 2024 · 1 comment
Open

fda_kmeans.fit_predict(X) #599

jack-pan-ai opened this issue Feb 25, 2024 · 1 comment
Labels

Comments

@jack-pan-ai
Copy link

Bug description summary


TypeError Traceback (most recent call last)
/var/folders/js/lpf4z00557sb1m38br8bzj_476fsrl/T/ipykernel_16178/3403943172.py in
8 random_state=0,
9 )
---> 10 fda_clusters = fda_kmeans.fit_predict(X)

~/miniconda3/envs/pytorch/lib/python3.9/site-packages/skfda/_utils/_sklearn_adapter.py in fit_predict(self, X, y)
157 y: object = None,
158 ) -> NDArrayInt:
--> 159 return super().fit_predict(X, y) # type: ignore[no-any-return]
160
161

~/miniconda3/envs/pytorch/lib/python3.9/site-packages/sklearn/base.py in fit_predict(self, X, y)
749 # non-optimized default implementation; override when a better
750 # method is possible for a given clustering algorithm
--> 751 self.fit(X)
752 return self.labels_
753

~/miniconda3/envs/pytorch/lib/python3.9/site-packages/skfda/ml/clustering/_kmeans.py in fit(self, X, y, sample_weight)
327 n_iter,
328 ) = (
--> 329 self._algorithm(
330 fdata=fdata,
331 random_state=random_state,

~/miniconda3/envs/pytorch/lib/python3.9/site-packages/skfda/ml/clustering/_kmeans.py in _algorithm(self, fdata, random_state)
266 centroids_old.data_matrix[...] = centroids.data_matrix
267
--> 268 distances_to_centroids = pairwise_metric(fdata, centroids)
269
270 self._update(

~/miniconda3/envs/pytorch/lib/python3.9/site-packages/skfda/misc/metrics/_utils.py in call(self, elem1, elem2)
181 ) -> NDArrayFloat:
182 """Evaluate the pairwise metric."""
--> 183 optimized = pairwise_metric_optimization(self.metric, elem1, elem2)
184
185 return (

~/miniconda3/envs/pytorch/lib/python3.9/site-packages/multimethod/init.py in call(self, *args, **kwargs)
419 """Resolve and dispatch to best method."""
420 params = self.signature.bind(*args, **kwargs).args if (kwargs and self.signature) else args
--> 421 func = self.dispatch(*params)
422 return func(*args, **kwargs)
423

~/miniconda3/envs/pytorch/lib/python3.9/site-packages/multimethod/init.py in dispatch(self, *args)
352 def dispatch(self, *args) -> Callable:
353 types = tuple(map(type, args))
--> 354 if not any(map(issubclass, types, self.generics)):
355 return self[types]
356 matches = {key for key in list(self) if isinstance(key, signature) and key.instances(*args)}

~/miniconda3/envs/pytorch/lib/python3.9/typing.py in subclasscheck(self, cls)
716
717 def subclasscheck(self, cls):
--> 718 raise TypeError("Subscripted generics cannot be used with"
719 " class and instance checks")
720

TypeError: Subscripted generics cannot be used with class and instance checks

Code to reproduce the bug

In your official example, https://fda.readthedocs.io/en/stable/auto_examples/full_examples/plot_aemet_unsupervised.html#sphx-glr-auto-examples-full-examples-plot-aemet-unsupervised-py


n_clusters = 5
n_init = 10

fda_kmeans = KMeans(
    n_clusters=n_clusters,
    n_init=n_init,
    metric=l2_distance,
    random_state=0,
)
fda_clusters = fda_kmeans.fit_predict(X)

Expected result

successfully work

Actual result

optimization error reported

Traceback (if an exception is raised)

No response

Software versions

scikit-fda version:0.9
OS: MAC 13.2.1 (22D68)

Additional context

No response

@vnmabus
Copy link
Member

vnmabus commented Feb 26, 2024

This is due to an error in one of our dependencies (coady/multimethod#113). While this is being investigated, I recommend installing an older version of multimethod:

pip install multimethod==1.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants