class_docstr: Bag-of-words representation for time series.
  
  This algorithm uses a sliding window to extract subsequences from the
  time series and transforms each subsequence into a word using the
  Piecewise Aggregate Approximation and the Symbolic Aggregate approXimation
  algorithms. Thus it transforms each time series into a bag of words.
  
  Parameters
  ----------
  window_size : int or float (default = 0.5)
      Length of the sliding window. If float, it represents
      a percentage of the size of each time series and must be
      between 0 and 1.
  
  word_size : int or float (default = 0.5)
      Length of the words. If float, it represents
      a percentage of the length of the sliding window and must be
      between 0. and 1.
  
  n_bins : int (default = 4)
      The number of bins to produce. It must be between 2 and
      ``min(n_timestamps, 26)``.
  
  strategy : 'uniform', 'quantile' or 'normal' (default = 'normal')
      Strategy used to define the widths of the bins:
  
      - 'uniform': All bins in each sample have identical widths
      - 'quantile': All bins in each sample have the same number of points
      - 'normal': Bin edges are quantiles from a standard normal distribution
  
  numerosity_reduction : bool (default = True)
      If True, delete sample-wise all but one occurence of back to back
      identical occurences of the same words.
  
  window_step : int or float (default = 1)
      Step of the sliding window. If float, it represents the percentage of
      the size of each time series and must be between 0 and 1. The window
      size will be computed as ``ceil(window_step * n_timestamps)``.
  
  threshold_std : int, float or None (default = 0.01)
      Threshold used to determine whether a subsequence is standardized.
      Subsequences whose standard deviations are lower than this threshold
      are not standardized. If None, all the subsequences are standardized.
  
  norm_mean : bool (default = True)
      If True, center each subseries before scaling.
  
  norm_std : bool (default = True)
      If True, scale each subseries to unit variance.
  
  overlapping : bool (default = True)
      If True, time points may belong to two bins when decreasing the size
      of the subsequence with the Piecewise Aggregate Approximation
      algorithm. If False, each time point belong to one single bin, but
      the size of the bins may vary.
  
  raise_warning : bool (default = False)
      If True, a warning is raised when the number of bins is smaller for
      at least one subsequence. In this case, you should consider decreasing
      the number of bins, using another strategy to compute the bins or
      removing the corresponding time series.
  
  alphabet : None or array-like, shape = (n_bins,)
      Alphabet to use. If None, the first `n_bins` letters of the Latin
      alphabet are used.
  
  References
  ----------
  .. [1] J. Lin, R. Khade and Y. Li, "Rotation-invariant similarity in time
         series using bag-of-patterns representation". Journal of Intelligent
         Information Systems, 39 (2), 287-315 (2012).
  
  Examples
  --------
  >>> import numpy as np
  >>> from pyts.bag_of_words import BagOfWords
  >>> X = np.arange(12).reshape(2, 6)
  >>> bow = BagOfWords(window_size=4, word_size=4)
  >>> bow.transform(X)
  array(['abcd', 'abcd'], dtype='<U4')
  >>> bow.set_params(numerosity_reduction=False)
  BagOfWords(...)
  >>> bow.transform(X)
  array(['abcd abcd abcd', 'abcd abcd abcd'], dtype='<U14')
class_docstr_tok: ["Bag-of-words","representation","for","time","series",".","This","algorithm","uses","a","sliding","window","to","extract","subsequences","from","the","time","series","and","transforms","each","subsequence","into","a","word","using","the","Piecewise","Aggregate","Approximation","and","the","Symbolic","Aggregate","approXimation","algorithms",".","Thus","it","transforms","each","time","series","into","a","bag","of","words",".","Parameters","--","--","--","--","--","window_size",":","int","or","float","(","default","=","0.5",")","Length","of","the","sliding","window",".","If","float",",","it","represents","a","percentage","of","the","size","of","each","time","series","and","must","be","between","0","and","1.","word_size",":","int","or","float","(","default","=","0.5",")","Length","of","the","words",".","If","float",",","it","represents","a","percentage","of","the","length","of","the","sliding","window","and","must","be","between","0.","and","1.","n_bins",":","int","(","default","=","4",")","The","number","of","bins","to","produce",".","It","must","be","between","2","and","``","min","(","n_timestamps",",","26",")","``",".","strategy",":","'uniform","'",",","'quantile","'","or","'normal","'","(","default","=","'normal","'",")","Strategy","used","to","define","the","widths","of","the","bins",":","-","'uniform","'",":","All","bins","in","each","sample","have","identical","widths","-","'quantile","'",":","All","bins","in","each","sample","have","the","same","number","of","points","-","'normal","'",":","Bin","edges","are","quantiles","from","a","standard","normal","distribution","numerosity_reduction",":","bool","(","default","=","True",")","If","True",",","delete","sample-wise","all","but","one","occurence","of","back","to","back","identical","occurences","of","the","same","words",".","window_step",":","int","or","float","(","default","=","1",")","Step","of","the","sliding","window",".","If","float",",","it","represents","the","percentage","of","the","size","of","each","time","series","and","must","be","between","0","and","1",".","The","window","size","will","be","computed","as","``","ceil","(","window_step","*","n_timestamps",")","``",".","threshold_std",":","int",",","float","or","None","(","default","=","0.01",")","Threshold","used","to","determine","whether","a","subsequence","is","standardized",".","Subsequences","whose","standard","deviations","are","lower","than","this","threshold","are","not","standardized",".","If","None",",","all","the","subsequences","are","standardized",".","norm_mean",":","bool","(","default","=","True",")","If","True",",","center","each","subseries","before","scaling",".","norm_std",":","bool","(","default","=","True",")","If","True",",","scale","each","subseries","to","unit","variance",".","overlapping",":","bool","(","default","=","True",")","If","True",",","time","points","may","belong","to","two","bins","when","decreasing","the","size","of","the","subsequence","with","the","Piecewise","Aggregate","Approximation","algorithm",".","If","False",",","each","time","point","belong","to","one","single","bin",",","but","the","size","of","the","bins","may","vary",".","raise_warning",":","bool","(","default","=","False",")","If","True",",","a","warning","is","raised","when","the","number","of","bins","is","smaller","for","at","least","one","subsequence",".","In","this","case",",","you","should","consider","decreasing","the","number","of","bins",",","using","another","strategy","to","compute","the","bins","or","removing","the","corresponding","time","series",".","alphabet",":","None","or","array-like",",","shape","=","(","n_bins",",",")","Alphabet","to","use",".","If","None",",","the","first","`","n_bins","`","letters","of","the","Latin","alphabet","are","used",".","References","--","--","--","--","--","..","[","1","]","J.","Lin",",","R.","Khade","and","Y.","Li",",","``","Rotation-invariant","similarity","in","time","series","using","bag-of-patterns","representation","''",".","Journal","of","Intelligent","Information","Systems",",","39","(","2",")",",","287-315","(","2012",")",".","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","from","pyts.bag_of_words","import","BagOfWords",">",">",">","X","=","np.arange","(","12",")",".reshape","(","2",",","6",")",">",">",">","bow","=","BagOfWords","(","window_size=4",",","word_size=4",")",">",">",">","bow.transform","(","X",")","array","(","[","'abcd","'",",","'abcd","'","]",",","dtype=","'","<","U4","'",")",">",">",">","bow.set_params","(","numerosity_reduction=False",")","BagOfWords","(","...",")",">",">",">","bow.transform","(","X",")","array","(","[","'abcd","abcd","abcd","'",",","'abcd","abcd","abcd","'","]",",","dtype=","'","<","U14","'",")"]
docstr: Transform each time series into a bag of words.
  
  Parameters
  ----------
  X : array-like, shape = (n_samples, n_timestamps)
      Data to transform.
  
  Returns
  -------
  X_new : array, shape = (n_samples,)
      Bags of words.
docstr_tok: ["Transform","each","time","series","into","a","bag","of","words",".","Parameters","--","--","--","--","--","X",":","array-like",",","shape","=","(","n_samples",",","n_timestamps",")","Data","to","transform",".","Returns","--","--","--","-","X_new",":","array",",","shape","=","(","n_samples",",",")","Bags","of","words","."]
code: def transform(self, X):
      """Transform each time series into a bag of words.
  
      Parameters
      ----------
      X : array-like, shape = (n_samples, n_timestamps)
          Data to transform.
  
      Returns
      -------
      X_new : array, shape = (n_samples,)
          Bags of words.
  
      """
      X = check_array(X, dtype="float64")
      n_samples, n_timestamps = X.shape
      (
          window_size,
          word_size,
          window_step,
          alphabet,
      ) = self._check_params(n_timestamps)
      n_windows = (
          n_timestamps - window_size + window_step
      ) // window_step
  
      # Standardize time series if quantile from standard normal distribution
      if self.strategy == "normal":
          X_scaled = StandardScaler().transform(X)
      else:
          X_scaled = X
  
      # Extract subsequences using a sliding window
      X_window = _windowed_view(
          X_scaled, n_samples, n_timestamps, window_size, window_step
      ).reshape(n_samples * n_windows, window_size)
  
      if self.threshold_std is not None:
          # Identify subsequences whose standard deviation below threshold
          idx = np.std(X_window, axis=1) < self.threshold_std
  
          if np.any(idx):
              # Subsequences with standard deviations below threshold
              X_paa = PiecewiseAggregateApproximation(
                  window_size=None,
                  output_size=word_size,
                  overlapping=self.overlapping,
              ).transform(X_window[idx])
  
              # Compute the bin edges
              discretizer = KBinsDiscretizer(
                  n_bins=self.n_bins,
                  strategy=self.strategy,
                  raise_warning=self.raise_warning,
              )
              bin_edges = discretizer._compute_bins(
                  X_scaled, n_samples, self.n_bins, self.strategy
              )
  
              # Tile the bin edges for subsequences from the same time series
              if self.strategy != "normal":
                  count = np.bincount(
                      np.floor_divide(np.nonzero(idx)[0], n_windows)
                  )
                  bin_edges = np.vstack(
                      [
                          np.tile(bin_edges[i], (count[i], 1))
                          for i in range(count.size)
                          if count[i] != 0
                      ]
                  )
  
              X_sax_below_thresh = alphabet[_digitize(X_paa, bin_edges)]
  
      # Subsequences with standard deviations above threshold
      if (self.threshold_std is None) or (not np.all(idx)):
          pipeline = make_pipeline(
              StandardScaler(
                  with_mean=self.norm_mean, with_std=self.norm_std
              ),
              PiecewiseAggregateApproximation(
                  window_size=None,
                  output_size=word_size,
                  overlapping=self.overlapping,
              ),
              SymbolicAggregateApproximation(
                  n_bins=self.n_bins,
                  strategy=self.strategy,
                  alphabet=self.alphabet,
                  raise_warning=self.raise_warning,
              ),
          )
          if self.threshold_std is None:
              X_sax_above_thresh = pipeline.fit_transform(X_window)
          else:
              X_sax_above_thresh = pipeline.fit_transform(
                  X_window[~idx]
              )
  
      # Concatenate SAX words
      if self.threshold_std is not None:
          if np.any(idx):
              if not np.all(idx):
                  X_sax = np.empty(
                      (n_samples * n_windows, word_size), dtype="<U1"
                  )
                  X_sax[idx] = X_sax_below_thresh
                  X_sax[~idx] = X_sax_above_thresh
              else:
                  X_sax = X_sax_below_thresh
          else:
              X_sax = X_sax_above_thresh
      else:
          X_sax = X_sax_above_thresh
      X_sax = X_sax.reshape(n_samples, n_windows, word_size)
  
      # Join letters to make words
      X_word = np.asarray(
          [
              ["".join(X_sax[i, j]) for j in range(n_windows)]
              for i in range(n_samples)
          ]
      )
  
      # Apply numerosity reduction
      if self.numerosity_reduction:
          not_equal = np.c_[
              X_word[:, 1:] != X_word[:, :-1], np.full(n_samples, True)
          ]
          X_bow = np.asarray(
              [
                  " ".join(X_word[i, not_equal[i]])
                  for i in range(n_samples)
              ]
          )
      else:
          X_bow = np.asarray(
              [" ".join(X_word[i]) for i in range(n_samples)]
          )
  
      return X_bow
  
imports: import numpy
  from math import ceil
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.pipeline import make_pipeline
  from sklearn.utils.validation import check_array
  from ..approximation import PiecewiseAggregateApproximation, SymbolicAggregateApproximation
  from ..base import UnivariateTransformerMixin
  from ..preprocessing import KBinsDiscretizer, StandardScaler
  from ..preprocessing.discretizer import _digitize
  from ..utils.utils import _windowed_view
label_desc: Use image node_id 3 for calling the BagOfWords obj's underlying member method code with example usage: obj.transform(X) and returns: X_bow