pyts.transformation.ShapeletTransform¶
-
class
pyts.transformation.ShapeletTransform(n_shapelets='auto', criterion='mutual_info', window_sizes='auto', window_steps=None, remove_similar=True, sort=False, verbose=0, random_state=None, n_jobs=None)[来源]¶ Shapelet变换算法。
Shapelet Transform算法从时间序列数据集中提取最具区分性的shapelets。shapelet被定义为时间序列中连续点的子集。提供了两个评估标准:互信息和F分数。
Parameters: - n_shapelets : int or ‘auto’ (default = ‘auto’)
需要保留的形状片段数量。如果设为'auto',则考虑n_timestamps // 2个形状片段,其中n_timestamps表示数据集中的时间点数量。请注意,如果在搜索过程中提取到的形状片段少于
n_shapelets,实际保留的数量可能会更少。- criterion : ‘mutual_info’ or ‘anova’ (default = ‘mutual_info’)
用于执行shapelets选择的标准。 'mutual_info'使用互信息,而'anova'使用 ANOVA F值。
- window_sizes : array-like or ‘auto ‘(default = ‘auto’)
滑动窗口的大小。如果设为'auto',窗口大小的范围将自动确定。 否则,所有元素必须是整数或浮点数。 如果是浮点数,每个元素代表每个时间序列大小的百分比, 必须在0到1之间;滑动窗口的大小将按
np.ceil(window_sizes * n_timestamps)计算。- window_steps : None or array-like (default = None)
滑动窗口的步长。如果为None,则每个
window_step等于1。否则,所有元素必须是整数或浮点数。在后一种情况下,每个元素代表每个时间序列大小的百分比,必须在0到1之间;滑动窗口的步长将计算为np.ceil(window_steps * n_timestamps)。当window_sizes='auto'时必须为None。- remove_similar : bool (default = True)
如果为True,将移除自相似的shapelets,仅保留得分最高的非自相似shapelets。当两个shapelets来自同一时间序列且至少有一个重叠索引时,即被视为自相似。
- sort : bool (default = False)
如果为True,则shapelet按其关联分数降序排列。如果为False,则顺序未定义。
- verbose : int (default = 0)
拟合时的详细程度:如果非零,则会打印进度信息。超过50时,输出将发送到标准输出。信息显示的频率随详细程度级别增加而提高。
- random_state : int, RandomState instance or None (default = None)
如果是整数,random_state是随机数生成器使用的种子; 如果是RandomState实例,random_state就是随机数生成器; 如果是None,则随机数生成器是
np.random使用的RandomState实例。仅在window_sizes='auto'时用于对数据集进行子采样以寻找最佳范围,或者在criterion=='mutual_info'时用于向数据添加微小噪声。- n_jobs : None or int (default = None)
用于
fit的并行任务数。如果设为-1,则任务数将设置为CPU核心数。
参考文献
[1] J. Lines, L. M. Davis, J. Hills 和 A. Bagnall, "用于时间序列分类的Shapelet变换"。数据挖掘与知识发现,289-297 (2012)。 示例
>>> from pyts.transformation import ShapeletTransform >>> X = [[0, 2, 3, 4, 3, 2, 1], ... [0, 1, 3, 4, 3, 4, 5], ... [2, 1, 0, 2, 1, 5, 4], ... [1, 2, 2, 1, 0, 3, 5]] >>> y = [0, 0, 1, 1] >>> st = ShapeletTransform(n_shapelets=2, window_sizes=[3]) >>> st.fit(X, y) ShapeletTransform(...) >>> len(st.shapelets_) 2 >>> st.indices_.shape (2, 3)
Attributes: - shapelets_ : array, shape = (n_shapelets,)
包含所选shapelets的数组。
- indices_ : array, shape = (n_shapelets, 3)
训练集中对应shapelet的索引。 第一列包含样本的索引。 第二列包含shapelet的起始索引(包含)。 第三列包含shapelet的结束索引(不包含)。
- scores_ : array, shape = (n_shapelets,)
与shapelets相关的分数。数值越高,区分度越强。 如果
criterion='mutual_info',则报告互信息分数。 如果criterion='anova',则报告F分数。- window_range_ : None or tuple
如果
window_sizes='auto',则表示窗口大小的范围。否则为None。
方法
__init__([n_shapelets, criterion, …])Initialize self. fit(X, y)Fit the model according to the given training data. fit_transform(X, y)Fit the model than transform the given training data. get_params([deep])Get parameters for this estimator. set_params(**params)Set the parameters of this estimator. transform(X)Transform the provided data. -
__init__(n_shapelets='auto', criterion='mutual_info', window_sizes='auto', window_steps=None, remove_similar=True, sort=False, verbose=0, random_state=None, n_jobs=None)[来源]¶ 初始化自身。查看 help(type(self)) 获取准确的签名信息。
-
fit(X, y)[来源]¶ 根据给定的训练数据拟合模型。
它在训练集中找到
n_shapelets个最佳shapelets。参数: - X : array-like, shape = (n_samples, n_timestamps)
单变量时间序列。
- y : array-like, shape = (n_samples,)
每个数据样本的类别标签。
返回值: - self : object
-
fit_transform(X, y)[来源]¶ 拟合模型然后转换给定的训练数据。
它在训练集中找到
n_shapelets个最佳shapelets,并计算它们与训练集之间的距离。参数: - X : array-like, shape = (n_samples, n_timestamps)
单变量时间序列。
- y : array-like, shape = (n_samples,)
每个数据样本的类别标签。
返回值: - X_new : array, shape = (n_samples, n_shapelets)
所选shapelets与样本之间的距离。
-
get_params(deep=True)¶ 获取此估计器的参数。
参数: - deep : bool, default=True
如果为True,将返回此估计器及其包含的子估计器的参数。
返回值: - params : dict
参数名称映射到对应的值。