Exemplo n.º 1
0
series of real numbers into a sequence of frequencies of words, and
illustrates the features obtained for two time series.
It is implemented as :class:`pyts.multivariate.transformation.WEASELMUSE`.
"""

# Author: Johann Faouzi <*****@*****.**>
# License: BSD-3-Clause

import numpy as np
import matplotlib.pyplot as plt
from pyts.datasets import load_basic_motions
from pyts.multivariate.transformation import WEASELMUSE
from sklearn.preprocessing import LabelEncoder

# Toy dataset
X_train, _, y_train, _ = load_basic_motions(return_X_y=True)
y_train = LabelEncoder().fit_transform(y_train)

# WEASEL+MUSE transformation
transformer = WEASELMUSE(word_size=2,
                         n_bins=2,
                         window_sizes=[12, 36],
                         chi2_threshold=15,
                         sparse=False)
X_weasel = transformer.fit_transform(X_train, y_train)

# Visualize the transformation for the first time series
plt.figure(figsize=(6, 4))
vocabulary_length = len(transformer.vocabulary_)
width = 0.3
plt.bar(np.arange(vocabulary_length) - width / 2,
Exemplo n.º 2
0
=====================

A joint recurrence plot is an extension of recurrence plots (
implemented as :class:`pyts.image.RecurrencePlot`) for multivariate time
series. A recurrence plot is built for each feature of the multivariate
time series, then the set of recurrence plots is reduced to one single
recurrence plot using the Hadamard product.
This example illustrates this transformation. It is implemented as
:class:`pyts.multivariate.image.JointRecurrencePlot`.
"""

# Author: Johann Faouzi <*****@*****.**>
# License: BSD-3-Clause

import matplotlib.pyplot as plt
from pyts.multivariate.image import JointRecurrencePlot
from pyts.datasets import load_basic_motions

X, _, _, _ = load_basic_motions(return_X_y=True)

# Recurrence plot transformation
jrp = JointRecurrencePlot(threshold='point', percentage=50)
X_jrp = jrp.fit_transform(X)

# Show the results for the first time series
plt.figure(figsize=(5, 5))
plt.imshow(X_jrp[0], cmap='binary', origin='lower')
plt.title('Joint Recurrence Plot', fontsize=18)
plt.tight_layout()
plt.show()
Exemplo n.º 3
0
# Author: Johann Faouzi <*****@*****.**>
# License: BSD-3-Clause

import numpy as np
import pytest
from sklearn.base import clone

from pyts.classification import SAXVSM
from pyts.datasets import load_gunpoint, load_basic_motions
from pyts.multivariate.image import JointRecurrencePlot
from pyts.multivariate.classification import MultivariateClassifier
from pyts.approximation import SymbolicFourierApproximation

X_uni, _, y_uni, _ = load_gunpoint(return_X_y=True)
X_multi, _, y_multi, _ = load_basic_motions(return_X_y=True)


@pytest.mark.parametrize('estimator, X, y', [
    (SymbolicFourierApproximation(n_bins=2), X_uni, None),
    (SymbolicFourierApproximation(n_bins=2, strategy='entropy'), X_uni, y_uni)
])
def test_univariate_transformer_mixin(estimator, X, y):
    sfa_1 = clone(estimator)
    sfa_2 = clone(estimator)
    np.testing.assert_array_equal(sfa_1.fit_transform(X, y),
                                  sfa_2.fit(X, y).transform(X))


@pytest.mark.parametrize('estimator, X, y',
                         [(JointRecurrencePlot(), X_multi, None),