Closed YannCabanes closed 9 months ago
Investigating on the issue https://github.com/tslearn-team/tslearn/issues/507, I found a recursion error in the function silhouette_score when the input parameter metric is callable.
silhouette_score
The error can be reproduced running the following code:
import numpy as np from tslearn.clustering.utils import silhouette_score from tslearn.metrics import dtw n_ts = 4 sz = 3 d = 2 X = np.random.randn(n_ts, sz, d) labels = [0] * (n_ts // 2) + [1] * (n_ts // 2) score = silhouette_score( X=X, labels=labels, metric=dtw) print(score)
The following error is returned:
RecursionError: maximum recursion depth exceeded while calling a Python object
The error is related to the end of the function silhouette_score:
def sklearn_metric(x, y): return metric(to_time_series(x.reshape((sz, d)), remove_nans=True), to_time_series(y.reshape((sz, d)), remove_nans=True)) metric = "precomputed" if sklearn_metric is None else sklearn_metric
Indeed, since metric is equal to sklearn_metric when sklearn_metric is callable, the function sklearn_metric is therefore calling itself.
metric
sklearn_metric
Investigating on the issue https://github.com/tslearn-team/tslearn/issues/507, I found a recursion error in the function
silhouette_score
when the input parameter metric is callable.The error can be reproduced running the following code:
The following error is returned:
The error is related to the end of the function
silhouette_score
:Indeed, since
metric
is equal tosklearn_metric
whensklearn_metric
is callable, the functionsklearn_metric
is therefore calling itself.