How to use the pyts.utils.numerosity_reduction 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 / pyts / transformation / transformation.py View on Github external
X_window = X[:, window_idx].reshape(n_samples * n_windows, -1)

        sfa = SFA(self.n_coefs, False, self.norm_mean,
                  self.norm_std, self.n_bins, self.quantiles,
                  self.variance_selection, self.variance_threshold)
        count = CountVectorizer(ngram_range=(1, 1))

        X_sfa = sfa.fit_transform(X_window)
        X_sfa = np.apply_along_axis(lambda x: ''.join(x),
                                    1,
                                    X_sfa).reshape(n_samples, -1)
        word_size = len(X_sfa[0, 0])
        if word_size == 1:
            count.set_params(tokenizer=self._tok)
        if self.numerosity_reduction:
            X_sfa = np.apply_along_axis(numerosity_reduction, 1, X_sfa)
        else:
            X_sfa = np.apply_along_axis(lambda x: ' '.join(x), 1, X_sfa)
        count.fit(X_sfa)

        for key, value in count.vocabulary_.items():
            self.vocabulary_[value] = key

        self._sfa = sfa
        self._count = count

        return self
github johannfaouzi / pyts / pyts / classification / classification.py View on Github external
# Check X
        X = check_array(X)
        n_samples, n_features = X.shape

        n_windows = n_features - self.window_size + 1
        X_window = np.asarray([X[:, i: i + self.window_size]
                               for i in range(n_windows)])
        X_window = X_window.reshape(n_samples * n_windows, -1, order='F')

        X_sfa = self._sfa.transform(X_window)
        X_sfa = np.apply_along_axis(lambda x: ''.join(x),
                                    1,
                                    X_sfa).reshape(n_samples, -1)
        if self.numerosity_reduction:
            X_sfa = np.apply_along_axis(numerosity_reduction, 1, X_sfa)
        else:
            X_sfa = np.apply_along_axis(lambda x: ' '.join(x), 1, X_sfa)
        tf = self._tfidf.transform(X_sfa) / self._tfidf.idf_
        y_pred = cosine_similarity(tf, self.tfidf_).argmax(axis=1)
        return self._classes[y_pred]
github johannfaouzi / pyts / pyts / bow / bow.py View on Github external
"to 1.")
        if self.window_size > n_features:
            raise ValueError("'window_size' must be lower than or equal to "
                             "the size of each time series.")
        if not isinstance(self.numerosity_reduction, (int, float)):
            raise TypeError("'numerosity_reduction' must be a boolean.")

        n_windows = n_features - self.window_size + 1
        X_window = np.asarray([X[:, i: i + self.window_size]
                               for i in range(n_windows)])
        X_window = X_window.reshape(n_samples * n_windows, -1, order='F')
        X_bow = np.apply_along_axis(lambda x: ''.join(x),
                                    1,
                                    X_window).reshape(n_samples, -1)
        if self.numerosity_reduction:
            X_bow = np.apply_along_axis(numerosity_reduction, 1, X_bow)
        else:
            X_bow = np.apply_along_axis(lambda x: ' '.join(x), 1, X_bow)
        return X_bow
github johannfaouzi / pyts / pyts / transformation / transformation.py View on Github external
# Check X
        X = check_array(X)
        n_samples, n_features = X.shape

        n_windows = n_features - self.window_size + 1
        X_window = np.asarray([X[:, i: i + self.window_size]
                               for i in range(n_windows)])
        X_window = X_window.reshape(n_samples * n_windows, -1, order='F')

        X_sfa = self._sfa.transform(X_window)
        X_sfa = np.apply_along_axis(lambda x: ''.join(x),
                                    1,
                                    X_sfa).reshape(n_samples, -1)
        if self.numerosity_reduction:
            X_sfa = np.apply_along_axis(numerosity_reduction, 1, X_sfa)
        else:
            X_sfa = np.apply_along_axis(lambda x: ' '.join(x), 1, X_sfa)
        tf = self._count.transform(X_sfa)
        return tf
github johannfaouzi / pyts / pyts / classification / classification.py View on Github external
sfa = SFA(self.n_coefs, False, self.norm_mean,
                  self.norm_std, self.n_bins, self.quantiles,
                  self.variance_selection, self.variance_threshold)
        tfidf = TfidfVectorizer(ngram_range=(1, 1), smooth_idf=self.smooth_idf,
                                sublinear_tf=self.sublinear_tf)

        X_sfa = sfa.fit_transform(X_window)
        X_sfa = np.apply_along_axis(lambda x: ''.join(x),
                                    1,
                                    X_sfa).reshape(n_samples, -1)
        word_size = len(X_sfa[0, 0])
        if word_size == 1:
            tfidf.set_params(tokenizer=self._tok)
        if self.numerosity_reduction:
            X_sfa = np.apply_along_axis(numerosity_reduction, 1, X_sfa)
        else:
            X_sfa = np.apply_along_axis(lambda x: ' '.join(x), 1, X_sfa)

        X_class = np.array([' '.join(X_sfa[y_ind == i])
                            for i in range(n_classes)])

        X_tfidf = tfidf.fit_transform(X_class)
        for key, value in tfidf.vocabulary_.items():
            self.vocabulary_[value] = key
        self._sfa = sfa
        self._tfidf = tfidf
        self.tfidf_ = X_tfidf
        return self