Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Multivariate time series.
y : array-like, shape = (n_samples,)
Class labels.
Returns
-------
self : object
"""
X = check_3d_array(X)
_, n_features, n_timestamps = X.shape
X_diff = np.abs(np.diff(X))
estimator = WEASEL(
word_size=self.word_size, n_bins=self.n_bins,
window_sizes=self.window_sizes, window_steps=self.window_steps,
anova=self.anova, drop_sum=self.drop_sum, norm_mean=self.norm_mean,
norm_std=self.norm_std, strategy=self.strategy,
chi2_threshold=self.chi2_threshold, sparse=self.sparse,
alphabet=self.alphabet
)
self._estimators = [clone(estimator) for _ in range(n_features)]
self._estimators_diff = [clone(estimator) for _ in range(n_features)]
self.vocabulary_ = {}
for i, transformer in enumerate(self._estimators):
transformer.fit(X[:, i, :], y)
self._update_vocabulary(str(i + 1), transformer, original=True)
y : array-like, shape = (n_samples,)
Class labels.
Returns
-------
X_new : array, shape = (n_samples, n_features_new)
Document-term matrix with relevant features only.
"""
X = check_3d_array(X)
n_samples, n_features, n_timestamps = X.shape
X_diff = np.abs(np.diff(X))
estimator = WEASEL(
word_size=self.word_size, n_bins=self.n_bins,
window_sizes=self.window_sizes, window_steps=self.window_steps,
anova=self.anova, drop_sum=self.drop_sum, norm_mean=self.norm_mean,
norm_std=self.norm_std, strategy=self.strategy,
chi2_threshold=self.chi2_threshold, sparse=self.sparse,
alphabet=self.alphabet
)
self._estimators = [clone(estimator) for _ in range(n_features)]
self._estimators_diff = [clone(estimator) for _ in range(n_features)]
self.vocabulary_ = {}
X_new = []
for i, transformer in enumerate(self._estimators):
X_new.append(transformer.fit_transform(X[:, i, :], y))
self._update_vocabulary(str(i + 1), transformer, original=True)
It is implemented as :class:`pyts.transformation.WEASEL`.
"""
# Author: Johann Faouzi
# License: BSD-3-Clause
import numpy as np
import matplotlib.pyplot as plt
from pyts.datasets import load_gunpoint
from pyts.transformation import WEASEL
# Toy dataset
X_train, _, y_train, _ = load_gunpoint(return_X_y=True)
# WEASEL transformation
weasel = WEASEL(word_size=2, n_bins=2, window_sizes=[12, 36], sparse=False)
X_weasel = weasel.fit_transform(X_train, y_train)
# Visualize the transformation for the first time series
plt.figure(figsize=(6, 4))
vocabulary_length = len(weasel.vocabulary_)
width = 0.3
plt.bar(np.arange(vocabulary_length) - width / 2, X_weasel[y_train == 1][0],
width=width, label='First time series in class 1')
plt.bar(np.arange(vocabulary_length) + width / 2, X_weasel[y_train == 2][0],
width=width, label='First time series in class 2')
plt.xticks(np.arange(vocabulary_length),
np.vectorize(weasel.vocabulary_.get)(np.arange(X_weasel[0].size)),
fontsize=12, rotation=60)
y_max = np.max(np.concatenate([X_weasel[y_train == 1][0],
X_weasel[y_train == 2][0]]))
plt.yticks(np.arange(y_max + 1), fontsize=12)