From 086434da1cda674aa95581bc1a1adf629e67f2c5 Mon Sep 17 00:00:00 2001 From: Romain Tavenard Date: Thu, 18 Jun 2020 15:47:47 +0200 Subject: [PATCH 1/4] Make deprecated code still usable (bugfix) --- tslearn/svm.py | 22 +++++++--------------- tslearn/tests/test_svm.py | 11 +++++++++++ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/tslearn/svm.py b/tslearn/svm.py index fa2c5dcb0..40d138d03 100644 --- a/tslearn/svm.py +++ b/tslearn/svm.py @@ -164,8 +164,8 @@ class TimeSeriesSVC(TimeSeriesSVMMixin, ClassifierMixin, n_support_ : array-like, dtype=int32, shape = [n_class] Number of support vectors for each class. - support_vectors_ : array of shape [n_SV, sz, d] - Support vectors in tslearn dataset format + support_vectors_ : list of arrays of shape [n_SV, sz, d] + List of support vectors in tslearn dataset format, one array per class dual_coef_ : array, shape = [n_class-1, n_SV] Coefficients of the support vector in the decision function. @@ -240,20 +240,12 @@ def n_iter_(self): 'it is non-trivial to access the underlying libsvm') return 1 - @deprecated + @deprecated() def support_vectors_time_series_(self, X=None): - """Support vectors as time series. - - Parameters - ---------- - X : array-like of shape=(n_ts, sz, d) - Training time series dataset. - """ - if X is not None: - warnings.warn('The use of ' - '`support_vectors_time_series_` is deprecated in ' - 'tslearn v0.4 and will be removed in v0.6. Use ' - '`support_vectors_` property instead.') + warnings.warn('The use of ' + '`support_vectors_time_series_` is deprecated in ' + 'tslearn v0.4 and will be removed in v0.6. Use ' + '`support_vectors_` property instead.') check_is_fitted(self, '_X_fit') return self._X_fit[self.svm_estimator_.support_] diff --git a/tslearn/tests/test_svm.py b/tslearn/tests/test_svm.py index d4983277f..b177788dc 100644 --- a/tslearn/tests/test_svm.py +++ b/tslearn/tests/test_svm.py @@ -22,3 +22,14 @@ def test_gamma_value_svm(): cdist_mat = cdist_gak(time_series, sigma=np.sqrt(gamma / 2.)) np.testing.assert_allclose(sklearn_X, cdist_mat) + + +def test_deprecated_still_work(): + n, sz, d = 5, 10, 3 + rng = np.random.RandomState(0) + X = rng.randn(n, sz, d) + y = rng.randint(low=0, high=2, size=n) + + clf = TimeSeriesSVC().fit(X, y) + np.testing.assert_equal(clf.support_vectors_time_series_().shape[1:], + X.shape[1:]) From 5b4f468938cecfe5098851a9d116f5de60b3405c Mon Sep 17 00:00:00 2001 From: Romain Tavenard Date: Thu, 18 Jun 2020 16:07:37 +0200 Subject: [PATCH 2/4] Similar stuff for TimeSeriesSVR --- tslearn/svm.py | 11 +++++------ tslearn/tests/test_svm.py | 7 ++++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tslearn/svm.py b/tslearn/svm.py index 40d138d03..4a6eab737 100644 --- a/tslearn/svm.py +++ b/tslearn/svm.py @@ -507,7 +507,7 @@ def n_iter_(self): 'it is non-trivial to access the underlying libsvm') return 1 - @deprecated + @deprecated() def support_vectors_time_series_(self, X=None): """Support vectors as time series. @@ -516,11 +516,10 @@ def support_vectors_time_series_(self, X=None): X : array-like of shape=(n_ts, sz, d) Training time series dataset. """ - if X is not None: - warnings.warn('The use of ' - '`support_vectors_time_series_` is deprecated in ' - 'tslearn v0.4 and will be removed in v0.6. Use ' - '`support_vectors_` property instead.') + warnings.warn('The use of ' + '`support_vectors_time_series_` is deprecated in ' + 'tslearn v0.4 and will be removed in v0.6. Use ' + '`support_vectors_` property instead.') check_is_fitted(self, '_X_fit') return self._X_fit[self.svm_estimator_.support_] diff --git a/tslearn/tests/test_svm.py b/tslearn/tests/test_svm.py index b177788dc..7c53e08dd 100644 --- a/tslearn/tests/test_svm.py +++ b/tslearn/tests/test_svm.py @@ -30,6 +30,7 @@ def test_deprecated_still_work(): X = rng.randn(n, sz, d) y = rng.randint(low=0, high=2, size=n) - clf = TimeSeriesSVC().fit(X, y) - np.testing.assert_equal(clf.support_vectors_time_series_().shape[1:], - X.shape[1:]) + for ModelClass in [TimeSeriesSVC, TimeSeriesSVR]: + clf = ModelClass().fit(X, y) + np.testing.assert_equal(clf.support_vectors_time_series_().shape[1:], + X.shape[1:]) From a3093233d89a1d86d6082306592e57e9649b4a20 Mon Sep 17 00:00:00 2001 From: Romain Tavenard Date: Thu, 18 Jun 2020 16:09:59 +0200 Subject: [PATCH 3/4] Removed docstring --- tslearn/svm.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tslearn/svm.py b/tslearn/svm.py index 4a6eab737..72fb35c8f 100644 --- a/tslearn/svm.py +++ b/tslearn/svm.py @@ -509,13 +509,6 @@ def n_iter_(self): @deprecated() def support_vectors_time_series_(self, X=None): - """Support vectors as time series. - - Parameters - ---------- - X : array-like of shape=(n_ts, sz, d) - Training time series dataset. - """ warnings.warn('The use of ' '`support_vectors_time_series_` is deprecated in ' 'tslearn v0.4 and will be removed in v0.6. Use ' From e355fe354ddcc965d83abe5072bba561b6babdb4 Mon Sep 17 00:00:00 2001 From: Romain Tavenard Date: Thu, 18 Jun 2020 17:12:01 +0200 Subject: [PATCH 4/4] Better deprecation message in the docs --- tslearn/svm.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tslearn/svm.py b/tslearn/svm.py index 72fb35c8f..f28ca7efd 100644 --- a/tslearn/svm.py +++ b/tslearn/svm.py @@ -240,7 +240,10 @@ def n_iter_(self): 'it is non-trivial to access the underlying libsvm') return 1 - @deprecated() + @deprecated('The use of ' + '`support_vectors_time_series_` is deprecated in ' + 'tslearn v0.4 and will be removed in v0.6. Use ' + '`support_vectors_` property instead.') def support_vectors_time_series_(self, X=None): warnings.warn('The use of ' '`support_vectors_time_series_` is deprecated in ' @@ -507,7 +510,10 @@ def n_iter_(self): 'it is non-trivial to access the underlying libsvm') return 1 - @deprecated() + @deprecated('The use of ' + '`support_vectors_time_series_` is deprecated in ' + 'tslearn v0.4 and will be removed in v0.6. Use ' + '`support_vectors_` property instead.') def support_vectors_time_series_(self, X=None): warnings.warn('The use of ' '`support_vectors_time_series_` is deprecated in '