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]

时间序列特定的支持向量回归器。

Parameters:
Cfloat, optional (default=1.0)

误差项的惩罚参数C。

kernelstring, optional (default=’gak’)

指定算法中使用的核类型。 它必须是‘gak’或sklearn.svm.SVC接受的核之一。 如果未给出,将使用‘gak’。如果给出了一个可调用对象,它用于从数据矩阵预计算核矩阵;该矩阵应为形状为(n_samples, n_samples)的数组。

degreeint, optional (default=3)

多项式核函数的次数('poly')。 所有其他核函数忽略此参数。

gammafloat, optional (default=’auto’)

‘gak’、‘rbf’、‘poly’ 和 ‘sigmoid’ 的核系数。 如果 gamma 是 ‘auto’,则:

  • 对于‘gak’核,它是基于训练集的采样计算的(参见tslearn.metrics.gamma_soft_dtw

  • 对于其他内核(例如‘rbf’),将使用1/n_features。

coef0float, optional (default=0.0)

核函数中的独立项。 它仅在‘poly’和‘sigmoid’中显著。

tolfloat, optional (default=1e-3)

停止准则的容差。

epsilonfloat, optional (default=0.1)

Epsilon在epsilon-SVR模型中。它指定了epsilon管,在该管内,训练损失函数中与实际值距离在epsilon内的预测点不会受到惩罚。

shrinkingboolean, optional (default=True)

是否使用收缩启发式方法。

cache_sizefloat, optional (default=200.0)

指定内核缓存的大小(以MB为单位)。

n_jobsint or None, optional (default=None)

用于GAK交叉相似矩阵计算的并行作业数。 None 表示1,除非在 joblib.parallel_backend 上下文中。 -1 表示使用所有处理器。更多详情请参阅scikit-learn的 Glossary

verboseint, default: 0

启用详细输出。请注意,此设置利用了libsvm中的每个进程运行时设置,如果启用,在多线程环境中可能无法正常工作。

max_iterint, optional (default=-1)

求解器内的迭代次数硬限制,或-1表示无限制。

Attributes:
support_array-like, shape = [n_SV]

支持向量的索引。

support_vectors_array of shape [n_SV, sz, d]

tslearn 数据集格式中的支持向量

dual_coef_array, shape = [1, n_SV]

决策函数中支持向量的系数。

coef_array, shape = [1, n_features]

分配给特征的权重(原始问题中的系数)。这仅在线性核的情况下可用。coef_ 是从 dual_coef_support_vectors_ 派生的只读属性。

intercept_array, shape = [1]

决策函数中的常量。

sample_weightarray-like, shape = [n_samples]

每个样本的个体权重

svm_estimator_sklearn.svm.SVR

底层的sklearn估计器

参考文献

快速全局对齐核。 Marco Cuturi。 ICML 2011。

示例

>>> 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(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  
(..., 64, 2)
>>> sv.shape[0] <= 20
True

方法

fit(X, y[, sample_weight])

根据给定的训练数据拟合SVM模型。

get_metadata_routing()

获取此对象的元数据路由。

get_params([deep])

获取此估计器的参数。

predict(X)

预测给定时间序列的类别。

score(X, y[, sample_weight])

返回预测的决定系数。

set_fit_request(*[, sample_weight])

请求传递给fit方法的元数据。

set_params(**params)

设置此估计器的参数。

set_score_request(*[, sample_weight])

传递给score方法的请求元数据。

fit(X, y, sample_weight=None)[source]

根据给定的训练数据拟合SVM模型。

Parameters:
Xarray-like of shape=(n_ts, sz, d)

时间序列数据集。

yarray-like of shape=(n_ts, )

时间序列标签。

sample_weightarray-like of shape (n_samples,), default=None

每个样本的权重。重新调整每个样本的C值。较高的权重会迫使分类器更加重视这些点。

get_metadata_routing()[source]

获取此对象的元数据路由。

请查看用户指南了解路由机制的工作原理。

Returns:
routingMetadataRequest

一个封装了路由信息的MetadataRequest

get_params(deep=True)[source]

获取此估计器的参数。

Parameters:
deepbool, default=True

如果为True,将返回此估计器及其包含的子对象(如果也是估计器)的参数。

Returns:
paramsdict

参数名称映射到它们的值。

predict(X)[source]

预测给定时间序列集合的类别。

Parameters:
Xarray-like of shape=(n_ts, sz, d)

时间序列数据集。

Returns:
array of shape=(n_ts, ) or (n_ts, dim_output), depending on the shape
of the target vector provided at training time.

预测目标

score(X, y, sample_weight=None)[source]

返回预测的确定系数。

决定系数\(R^2\)定义为\((1 - \frac{u}{v})\),其中\(u\)是残差平方和((y_true - y_pred)** 2).sum(),而\(v\)是总平方和((y_true - y_true.mean()) ** 2).sum()。最佳可能得分为1.0,且可能为负(因为模型可能任意更差)。一个总是预测y期望值的常数模型,忽略输入特征,将获得\(R^2\)得分为0.0。

Parameters:
Xarray-like of shape (n_samples, n_features)

测试样本。对于某些估计器,这可能是一个预计算的内核矩阵或一个形状为(n_samples, n_samples_fitted)的通用对象列表,其中n_samples_fitted是用于估计器拟合的样本数量。

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

X的真实值。

sample_weightarray-like of shape (n_samples,), default=None

样本权重。

Returns:
scorefloat

\(R^2\)self.predict(X) 相对于 y

注释

在回归器上调用score时使用的\(R^2\)分数从0.23版本开始使用multioutput='uniform_average',以保持与r2_score()的默认值一致。这影响了所有多输出回归器的score方法(除了MultiOutputRegressor)。

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') TimeSeriesSVR[source]

传递给fit方法的请求元数据。

请注意,此方法仅在 enable_metadata_routing=True 时相关(参见 sklearn.set_config())。 请参阅 用户指南 了解路由机制的工作原理。

每个参数的选项是:

  • True: 请求元数据,并在提供时传递给 fit。如果未提供元数据,则忽略该请求。

  • False: 不请求元数据,元估计器不会将其传递给 fit

  • None: 不请求元数据,如果用户提供了元数据,元估计器将引发错误。

  • str: 元数据应该使用这个给定的别名传递给元估计器,而不是原始名称。

默认值(sklearn.utils.metadata_routing.UNCHANGED)保留现有的请求。这允许您更改某些参数的请求,而不更改其他参数。

版本1.3中的新功能。

注意

此方法仅在此估计器用作元估计器的子估计器时相关,例如在Pipeline内部使用。否则它没有效果。

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

fit 方法中 sample_weight 参数的元数据路由。

Returns:
selfobject

更新后的对象。

set_params(**params)[source]

设置此估计器的参数。

该方法适用于简单的估计器以及嵌套对象(如Pipeline)。后者具有形式为<component>__<parameter>的参数,以便可以更新嵌套对象的每个组件。

Parameters:
**paramsdict

估计器参数。

Returns:
selfestimator instance

估计器实例。

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') TimeSeriesSVR[source]

传递给score方法的请求元数据。

请注意,此方法仅在 enable_metadata_routing=True 时相关(参见 sklearn.set_config())。 请参阅 用户指南 了解路由机制的工作原理。

每个参数的选项是:

  • True: 请求元数据,并在提供时传递给 score。如果未提供元数据,则忽略该请求。

  • False: 不请求元数据,元估计器不会将其传递给 score

  • None: 不请求元数据,如果用户提供了元数据,元估计器将引发错误。

  • str: 元数据应该使用这个给定的别名传递给元估计器,而不是原始名称。

默认值(sklearn.utils.metadata_routing.UNCHANGED)保留现有的请求。这允许您更改某些参数的请求,而不更改其他参数。

版本1.3中的新功能。

注意

此方法仅在此估计器用作元估计器的子估计器时相关,例如在Pipeline内部使用。否则它没有效果。

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

元数据路由用于score中的sample_weight参数。

Returns:
selfobject

更新后的对象。