Skip to content

Commit

Permalink
[MRG] Bugfix: deprecated method in svm classes was unavailable (#267)
Browse files Browse the repository at this point in the history
* Make deprecated code still usable (bugfix)

* Similar stuff for TimeSeriesSVR

* Removed docstring

* Better deprecation message in the docs
  • Loading branch information
rtavenar authored Jun 18, 2020
1 parent f6167f5 commit 6d24eef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
46 changes: 18 additions & 28 deletions tslearn/svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -240,20 +240,15 @@ 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):
"""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_]

Expand Down Expand Up @@ -515,20 +510,15 @@ 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):
"""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_]

Expand Down
12 changes: 12 additions & 0 deletions tslearn/tests/test_svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ 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)

for ModelClass in [TimeSeriesSVC, TimeSeriesSVR]:
clf = ModelClass().fit(X, y)
np.testing.assert_equal(clf.support_vectors_time_series_().shape[1:],
X.shape[1:])

0 comments on commit 6d24eef

Please sign in to comment.