tslearn-team / tslearn

The machine learning toolkit for time series analysis in Python
https://tslearn.readthedocs.io
BSD 2-Clause "Simplified" License
2.92k stars 342 forks source link

ImportError: cannot import name 'pinv2' from 'scipy.linalg' #444

Open Alan-Wolf-VN opened 1 year ago

Alan-Wolf-VN commented 1 year ago

Describe the bug Cannot import TimeSeriesKMeans from tslearn.clustering. The reason can be that scipy.linalg.pinv2 was deprecated with version 1.7 and removed with version 1.9. The functionality has been subsumed by scipy.linalg.pinv:

ImportError Traceback (most recent call last) C:\Users\NAMTRA~1\AppData\Local\Temp/ipykernel_9540/1246615330.py in ----> 1 from tslearn.clustering import TimeSeriesKMeans

~\AppData\Roaming\Python\Python39\site-packages\tslearn\clustering__init__.py in 6 details. 7 """ ----> 8 from .kshape import KShape 9 from .utils import (EmptyClusterError, silhouette_score, 10 TimeSeriesCentroidBasedClusteringMixin)

~\AppData\Roaming\Python\Python39\site-packages\tslearn\clustering\kshape.py in 9 from tslearn.preprocessing import TimeSeriesScalerMeanVariance 10 from tslearn.utils import to_time_series_dataset, check_dims ---> 11 from tslearn.metrics import cdist_normalized_cc, y_shifted_sbd_vec 12 from tslearn.bases import BaseModelPackage, TimeSeriesBaseEstimator 13

~\AppData\Roaming\Python\Python39\site-packages\tslearn\metrics__init__.py in 15 sakoe_chiba_mask, itakura_mask, 16 lcss, lcss_path, lcss_path_from_metric) ---> 17 from .ctw import ctw_path, ctw, cdist_ctw 18 from .sax import cdist_sax 19 from .softdtw_variants import (cdist_soft_dtw, cdist_gak,

~\AppData\Roaming\Python\Python39\site-packages\tslearn\metrics\ctw.py in ----> 1 from sklearn.cross_decomposition import CCA 2 from .dtw_variants import dtw_path 3 from .utils import _cdist_generic 4 from ..utils import to_time_series 5 import numpy as np

~\Anaconda3\lib\site-packages\sklearn\cross_decomposition__init__.py in ----> 1 from ._pls import PLSCanonical, PLSRegression, PLSSVD, CCA 2 3 all = ['PLSCanonical', 'PLSRegression', 'PLSSVD', 'CCA']

~\Anaconda3\lib\site-packages\sklearn\cross_decomposition_pls.py in 10 11 import numpy as np ---> 12 from scipy.linalg import pinv2, svd 13 14 from ..base import BaseEstimator, RegressorMixin, TransformerMixin

To Reproduce from tslearn.clustering import TimeSeriesKMeans

Expected behavior import tslearn.clustering without any error message

Environment (please complete the following information):

VaishU2235 commented 1 year ago

I was able to recreate the issue from my end using the following code:

!pip install scikit-learn==0.24
!pip install scipy==1.9
!pip install tslearn
from tslearn.clustering import TimeSeriesKMeans

This issue was fixed in scikit-learn 1.0.X

!pip install scikit-learn==1.0
!pip install scipy==1.9
!pip install tslearn
from tslearn.clustering import TimeSeriesKMeans

Is not throwing any errors for me. Please use scikit-learn>=1.0 to solve the issue.