# tslearn.svm.TimeSeriesSVR¶

class tslearn.svm.TimeSeriesSVR(C=1.0, kernel='gak', degree=3, gamma='auto', coef0=0.0, tol=0.001, epsilon=0.1, shrinking=True, cache_size=200, n_jobs=None, verbose=0, max_iter=-1)[source]

Time-series specific Support Vector Regressor.

Parameters: C : float, optional (default=1.0) Penalty parameter C of the error term. kernel : string, optional (default=’gak’) Specifies the kernel type to be used in the algorithm. It must be one of ‘gak’ or a kernel accepted by sklearn.svm.SVC. If none is given, ‘gak’ will be used. If a callable is given it is used to pre-compute the kernel matrix from data matrices; that matrix should be an array of shape (n_samples, n_samples). degree : int, optional (default=3) Degree of the polynomial kernel function (‘poly’). Ignored by all other kernels. gamma : float, optional (default=’auto’) Kernel coefficient for ‘gak’, ‘rbf’, ‘poly’ and ‘sigmoid’. If gamma is ‘auto’ then: for ‘gak’ kernel, it is computed based on a sampling of the training set (cf tslearn.metrics.gamma_soft_dtw) for other kernels (eg. ‘rbf’), 1/n_features will be used. coef0 : float, optional (default=0.0) Independent term in kernel function. It is only significant in ‘poly’ and ‘sigmoid’. tol : float, optional (default=1e-3) Tolerance for stopping criterion. epsilon : float, optional (default=0.1) Epsilon in the epsilon-SVR model. It specifies the epsilon-tube within which no penalty is associated in the training loss function with points predicted within a distance epsilon from the actual value. shrinking : boolean, optional (default=True) Whether to use the shrinking heuristic. cache_size : float, optional (default=200.0) Specify the size of the kernel cache (in MB). n_jobs : int or None, optional (default=None) The number of jobs to run in parallel for GAK cross-similarity matrix computations. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See scikit-learns’ Glossary for more details. verbose : int, default: 0 Enable verbose output. Note that this setting takes advantage of a per-process runtime setting in libsvm that, if enabled, may not work properly in a multithreaded context. max_iter : int, optional (default=-1) Hard limit on iterations within solver, or -1 for no limit. support_ : array-like, shape = [n_SV] Indices of support vectors. support_vectors_ : array of shape [n_SV, sz, d] Support vectors in tslearn dataset format dual_coef_ : array, shape = [1, n_SV] Coefficients of the support vector in the decision function. coef_ : array, shape = [1, n_features] Weights assigned to the features (coefficients in the primal problem). This is only available in the case of a linear kernel. coef_ is readonly property derived from dual_coef_ and support_vectors_. intercept_ : array, shape = [1] Constants in decision function. sample_weight : array-like, shape = [n_samples] Individual weights for each sample svm_estimator_ : sklearn.svm.SVR The underlying sklearn estimator

References

Fast Global Alignment Kernels. Marco Cuturi. ICML 2011.

Examples

>>> from tslearn.generators import random_walk_blobs
>>> X, y = random_walk_blobs(n_ts_per_blob=10, sz=64, d=2, n_blobs=2)
>>> import numpy
>>> y = y.astype(numpy.float) + numpy.random.randn(20) * .1
>>> reg = TimeSeriesSVR(kernel="gak", gamma="auto")
>>> reg.fit(X, y).predict(X).shape
(20,)
>>> sv = reg.support_vectors_
>>> sv.shape  # doctest: +ELLIPSIS
(..., 64, 2)
>>> sv.shape[0] <= 20
True


Methods

 fit(X, y[, sample_weight]) Fit the SVM model according to the given training data. get_params([deep]) Get parameters for this estimator. predict(X) Predict class for a given set of time series. score(X, y[, sample_weight]) Return the coefficient of determination $$R^2$$ of the prediction. set_params(**params) Set the parameters of this estimator. support_vectors_time_series_([X]) DEPRECATED: The use of support_vectors_time_series_ is deprecated in tslearn v0.4 and will be removed in v0.6.
fit(X, y, sample_weight=None)[source]

Fit the SVM model according to the given training data.

Parameters: X : array-like of shape=(n_ts, sz, d) Time series dataset. y : array-like of shape=(n_ts, ) Time series labels. sample_weight : array-like of shape (n_samples,), default=None Per-sample weights. Rescale C per sample. Higher weights force the classifier to put more emphasis on these points.
get_params(deep=True)[source]

Get parameters for this estimator.

Parameters: deep : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators. params : dict Parameter names mapped to their values.
predict(X)[source]

Predict class for a given set of time series.

Parameters: X : array-like of shape=(n_ts, sz, d) Time series dataset. array of shape=(n_ts, ) or (n_ts, dim_output), depending on the shape of the target vector provided at training time. Predicted targets
score(X, y, sample_weight=None)[source]

Return the coefficient of determination $$R^2$$ of the prediction.

The coefficient $$R^2$$ is defined as $$(1 - \frac{u}{v})$$, where $$u$$ is the residual sum of squares ((y_true - y_pred) ** 2).sum() and $$v$$ is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a $$R^2$$ score of 0.0.

Parameters: X : array-like of shape (n_samples, n_features) Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator. y : array-like of shape (n_samples,) or (n_samples, n_outputs) True values for X. sample_weight : array-like of shape (n_samples,), default=None Sample weights. score : float $$R^2$$ of self.predict(X) wrt. y.

Notes

The $$R^2$$ score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_params(**params)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters: **params : dict Estimator parameters. self : estimator instance Estimator instance.
support_vectors_time_series_(X=None)[source]

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.