How to use the pyts.bow.BOW 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 / plot_bow.py View on Github external
# Parameters
n_samples = 100
n_features = 30
n_bins = 4
window_size = 1
alphabet = np.array([chr(i) for i in range(97, 97 + n_bins)])

# Toy dataset
rng = np.random.RandomState(41)
X = alphabet[rng.randint(n_bins, size=(n_samples, n_features))]

# Bag-of-words transformation
bow = BOW(window_size, numerosity_reduction=False)
X_bow = bow.fit_transform(X)
bow_num = BOW(window_size, numerosity_reduction=True)
X_bow_num = bow_num.fit_transform(X)

print("Original time series:")
print(X[0])
print("\n")
print("Bag of words without numerosity reduction:")
print(''.join(["{", X_bow[0].replace(" ", ", "), "}"]))
print("\n")
print("Bag of words with numerosity reduction:")
print(''.join(["{", X_bow_num[0].replace(" ", ", "), "}"]))
github johannfaouzi / pyts / examples / plot_bow.py View on Github external
import numpy as np
from pyts.bow import BOW

# Parameters
n_samples = 100
n_features = 30
n_bins = 4
window_size = 1
alphabet = np.array([chr(i) for i in range(97, 97 + n_bins)])

# Toy dataset
rng = np.random.RandomState(41)
X = alphabet[rng.randint(n_bins, size=(n_samples, n_features))]

# Bag-of-words transformation
bow = BOW(window_size, numerosity_reduction=False)
X_bow = bow.fit_transform(X)
bow_num = BOW(window_size, numerosity_reduction=True)
X_bow_num = bow_num.fit_transform(X)

print("Original time series:")
print(X[0])
print("\n")
print("Bag of words without numerosity reduction:")
print(''.join(["{", X_bow[0].replace(" ", ", "), "}"]))
print("\n")
print("Bag of words with numerosity reduction:")
print(''.join(["{", X_bow_num[0].replace(" ", ", "), "}"]))
github johannfaouzi / pyts / pyts / classification / classification.py View on Github external
if not isinstance(self.smooth_idf, (int, float)):
            raise TypeError("'smooth_idf' must be a boolean.")
        if not isinstance(self.sublinear_tf, (int, float)):
            raise TypeError("'sublinear_tf' must be a boolean.")

        X, y = check_X_y(X, y)
        check_classification_targets(y)
        le = LabelEncoder()
        y_ind = le.fit_transform(y)
        self._classes = le.classes_
        n_classes = self._classes.size

        # SAX and BOW transformations
        sax = SAX(self.n_bins, self.quantiles)
        X_sax = sax.fit_transform(X)
        bow = BOW(self.window_size, self.numerosity_reduction)
        X_bow = bow.fit_transform(X_sax)

        X_class = [' '.join(X_bow[y_ind == classe])
                   for classe in range(n_classes)]

        tfidf = TfidfVectorizer(norm=None,
                                use_idf=self.use_idf,
                                smooth_idf=self.smooth_idf,
                                sublinear_tf=self.sublinear_tf)
        if self.window_size == 1:
            tfidf.set_params(tokenizer=self._tok)
        self.tfidf_ = tfidf.fit_transform(X_class)
        self.vocabulary_ = {value: key for key, value in
                            tfidf.vocabulary_.items()}
        self.stop_words_ = tfidf.stop_words
        if self.use_idf: