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

[MRG] Bugfix: deprecated method in svm classes was unavailable #267

Merged
merged 4 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:])