How to use the pyts.datasets.load_gunpoint function in pyts

To help you get started, we’ve selected a few pyts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github johannfaouzi / pyts / examples / bag_of_words / plot_bow.py View on Github external
of the sliding window is equal to the size of the sliding window, making the
subseries non-overlapping. It is common to use a step of 1 for the sliding
window, which is the default behavior. It is implemented as
:class:`pyts.bag_of_words.BagOfWords`.
"""

# Author: Johann Faouzi 
# License: BSD-3-Clause

import matplotlib.pyplot as plt
import numpy as np
from pyts.bag_of_words import BagOfWords
from pyts.datasets import load_gunpoint

# Load the dataset and perform the transformation
X, _, _, _ = load_gunpoint(return_X_y=True)
window_size, word_size = 30, 5
bow = BagOfWords(window_size=window_size, word_size=word_size,
                 window_step=window_size, numerosity_reduction=False)
X_bow = bow.transform(X)

# Plot the considered subseries
plt.figure(figsize=(10, 4))
splits_series = np.linspace(0, X.shape[1], 1 + X.shape[1] // window_size,
                            dtype='int64')
for start, end in zip(splits_series[:-1],
                      np.clip(splits_series[1:] + 1, 0, X.shape[1])):
    plt.plot(np.arange(start, end), X[0, start:end], 'o-', lw=1, ms=1)

# Plot the corresponding letters
splits_letters = np.linspace(0, X.shape[1],
                             1 + word_size * X.shape[1] // window_size)
github johannfaouzi / pyts / examples / classification / plot_bossvs.py View on Github external
as a tfidf vector. For an unlabeled time series, the predicted label is
the label of the tfidf vector giving the highest cosine similarity with
the tf vector of the unlabeled time series.
It is implemented as :class:`pyts.classification.BOSSVS`.
"""

# Author: Johann Faouzi 
# License: BSD-3-Clause

import numpy as np
import matplotlib.pyplot as plt
from pyts.classification import BOSSVS
from pyts.datasets import load_gunpoint

# Toy dataset
X_train, X_test, y_train, y_test = load_gunpoint(return_X_y=True)

# BOSSVS transformation
bossvs = BOSSVS(word_size=2, n_bins=3, window_size=10)
bossvs.fit(X_train, y_train)
tfidf = bossvs.tfidf_
vocabulary_length = len(bossvs.vocabulary_)
X_new = bossvs.decision_function(X_test)

# Visualize the transformation
plt.figure(figsize=(14, 5))
width = 0.4

plt.subplot(121)
plt.bar(np.arange(vocabulary_length) - width / 2, tfidf[0],
        width=width, label='Class 1')
plt.bar(np.arange(vocabulary_length) + width / 2, tfidf[1],
github johannfaouzi / pyts / examples / classification / plot_saxvsm.py View on Github external
as a tfidf vector. For an unlabeled time series, the predicted label is
the label of the tfidf vector giving the highest cosine similarity with
the tf vector of the unlabeled time series.
It is implemented as :class:`pyts.classification.SAXVSM`.
"""

# Author: Johann Faouzi 
# License: BSD-3-Clause

import numpy as np
import matplotlib.pyplot as plt
from pyts.classification import SAXVSM
from pyts.datasets import load_gunpoint

# Toy dataset
X_train, X_test, y_train, y_test = load_gunpoint(return_X_y=True)

# SAXVSM transformation
saxvsm = SAXVSM(window_size=15, word_size=3, n_bins=2,
                strategy='uniform')
saxvsm.fit(X_train, y_train)
tfidf = saxvsm.tfidf_
vocabulary_length = len(saxvsm.vocabulary_)
X_new = saxvsm.decision_function(X_test)

# Visualize the transformation
plt.figure(figsize=(14, 5))
width = 0.4

plt.subplot(121)
plt.bar(np.arange(vocabulary_length) - width / 2, tfidf[0],
        width=width, label='Class 1')
github johannfaouzi / pyts / examples / datasets / plot_load_gunpoint.py View on Github external
their sides. They point with their index fingers to a target for
approximately one second, and then return their hands to their sides.
For both classes, we tracked the centroid of the actor's right hands
in both X- and Y-axes, which appear to be highly correlated. The
data in the archive is just the X-axis.
It is implemented as :func:`pyts.datasets.load_gunpoint`.
"""

# Author: Johann Faouzi 
# License: BSD-3-Clause

import matplotlib.pyplot as plt
from pyts.datasets import load_gunpoint


X_train, X_test, y_train, y_test = load_gunpoint(return_X_y=True)
n_samples_per_plot = 3

plt.figure(figsize=(12, 8))

for i, (X, y, set_, class_,) in enumerate(zip(
    [X_train, X_train, X_test, X_test],
    [y_train, y_train, y_test, y_test],
    ['Training', 'Training', 'Test', 'Test'],
    [1, 2, 1, 2]
)):
    plt.subplot(2, 2, i + 1)
    for j in range(n_samples_per_plot):
        plt.plot(X[y == class_][j], 'C0')
    plt.title('{} set - class {}'.format(set_, class_), fontsize=16)

plt.suptitle('GunPoint dataset', fontsize=20)
github johannfaouzi / pyts / examples / transformation / plot_boss.py View on Github external
builds features representing frequencies of each word for each time series.
This example illustrates the words and the frequencies of these words that
have been learned by this algorithm.
It is implemented as :class:`pyts.transformation.BOSS`.
"""

# 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 BOSS

# Toy dataset
X_train, _, y_train, _ = load_gunpoint(return_X_y=True)

# BOSS transformation
boss = BOSS(word_size=2, n_bins=4, window_size=12, sparse=False)
X_boss = boss.fit_transform(X_train)

# Visualize the transformation for the first time series
plt.figure(figsize=(6, 4))
vocabulary_length = len(boss.vocabulary_)
width = 0.3
plt.bar(np.arange(vocabulary_length) - width / 2, X_boss[y_train == 1][0],
        width=width, label='First time series in class 1')
plt.bar(np.arange(vocabulary_length) + width / 2, X_boss[y_train == 2][0],
        width=width, label='First time series in class 2')
plt.xticks(np.arange(vocabulary_length),
           np.vectorize(boss.vocabulary_.get)(np.arange(X_boss[0].size)),
           fontsize=12)
github johannfaouzi / pyts / examples / preprocessing / plot_transformers.py View on Github external
Two transformers are made available:

* :class:`pyts.preprocessing.PowerTransformer`
* :class:`pyts.preprocessing.QuantileTransformer`.

This example illustrates the transformation from both algorithms.
"""

# Author: Johann Faouzi 
# License: BSD-3-Clause

import matplotlib.pyplot as plt
from pyts.datasets import load_gunpoint
from pyts.preprocessing import PowerTransformer, QuantileTransformer

X, _, _, _ = load_gunpoint(return_X_y=True)
n_timestamps = X.shape[1]

# Transform the data with different transformation algorithms
X_power = PowerTransformer().transform(X)
X_quantile = QuantileTransformer(n_quantiles=n_timestamps).transform(X)

# Show the results for the first time series
plt.figure(figsize=(6, 4))
plt.plot(X[0], '--', label='Original')
plt.plot(X_power[0], '--', label='PowerTransformer')
plt.plot(X_quantile[0], '--', label='QuantileTransformer')
plt.legend(loc='best', fontsize=8)
plt.title('Transforming time series', fontsize=16)
plt.tight_layout()
plt.show()
github johannfaouzi / pyts / examples / image / plot_rp.py View on Github external
Recurrence Plot
===============

A recurrence plot is an image obtained from a time series, representing the
distances between each time point. The image can be binarized using a
threshold. It is implemented as :class:`pyts.image.RecurrencePlot`.
"""

# Author: Johann Faouzi 
# License: BSD-3-Clause

import matplotlib.pyplot as plt
from pyts.image import RecurrencePlot
from pyts.datasets import load_gunpoint

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

# Recurrence plot transformation
rp = RecurrencePlot(threshold='point', percentage=20)
X_rp = rp.fit_transform(X)

# Show the results for the first time series
plt.figure(figsize=(5, 5))
plt.imshow(X_rp[0], cmap='binary', origin='lower')
plt.title('Recurrence Plot', fontsize=16)
plt.tight_layout()
plt.show()
github johannfaouzi / pyts / examples / image / plot_mtf.py View on Github external
A Markov Transition Field is an image obtained from a time series, representing
a field of transition probabilities for a discretized time series. Different
strategies can be used to bin time series. his example illustrates the
transformation on the first sample of the *GunPoint* dataset.
It is implemented as :class:`pyts.image.MarkovTransitionField`.
"""

# Author: Johann Faouzi 
# License: BSD-3-Clause

import matplotlib.pyplot as plt
from pyts.image import MarkovTransitionField
from pyts.datasets import load_gunpoint

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

# MTF transformation
mtf = MarkovTransitionField(image_size=24)
X_mtf = mtf.fit_transform(X)

# Show the image for the first time series
plt.figure(figsize=(5, 5))
plt.imshow(X_mtf[0], cmap='rainbow', origin='lower')
plt.title('Markov Transition Field', fontsize=18)
plt.colorbar(fraction=0.0457, pad=0.04)
plt.tight_layout()
plt.show()
github johannfaouzi / pyts / examples / metrics / plot_dtw.py View on Github external
compare the results with different variants of DTW. It is implemented
as :func:`pyts.metrics.dtw`.
"""

# Author: Johann Faouzi 
# License: BSD-3-Clause

import numpy as np
import matplotlib.pyplot as plt
from pyts.datasets import load_gunpoint
from pyts.metrics import dtw, itakura_parallelogram, sakoe_chiba_band
from pyts.metrics.dtw import (cost_matrix, accumulated_cost_matrix,
                              _return_path, _blurred_path_region)

# Parameters
X, _, _, _ = load_gunpoint(return_X_y=True)
x, y = X[0], X[1]

# To compare time series of different lengths, we remove some observations
mask = np.ones(x.size)
mask[::5] = 0
y = y[mask.astype(bool)]
n_timestamps_1, n_timestamps_2 = x.size, y.size

plt.figure(figsize=(10, 8))
timestamps_1 = np.arange(n_timestamps_1 + 1)
timestamps_2 = np.arange(n_timestamps_2 + 1)

# Dynamic Time Warping: classic
dtw_classic, path_classic = dtw(x, y, dist='square',
                                method='classic', return_path=True)
matrix_classic = np.zeros((n_timestamps_2 + 1, n_timestamps_1 + 1))
github johannfaouzi / pyts / examples / transformation / plot_weasel.py View on Github external
word for each time series.
This example illustrates the words and the frequencies of these words that
have been learned by this algorithm.
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)