class_docstr: Contractable Bag of Symbolic Fourier Approximation Symbols (cBOSS).
  
  Implementation of BOSS Ensemble from Schäfer (2015) with refinements
  described in Middlehurst, Vickers and Bagnall (2019). [1, 2]_
  
  Overview: Input "n" series of length "m" and cBOSS randomly samples
  `n_parameter_samples` parameter sets, evaluating each with LOOCV. It then
  retains `max_ensemble_size` classifiers with the highest accuracy
  There are three primary parameters:
      - alpha: alphabet size
      - w: window length
      - l: word length.
  
  For any combination, a single BOSS slides a window length "w" along the
  series. The "w" length window is shortened to an "l" length word by
  taking a Fourier transform and keeping the first l/2 complex coefficients.
  These "l" coefficients are then discretised into "alpha" possible values,
  to form a word length "l". A histogram of words for each
  series is formed and stored.
  
  Fit involves finding "n" histograms.
  
  Predict uses 1 nearest neighbor with a bespoke BOSS distance function.
  
  Parameters
  ----------
  n_parameter_samples : int, default = 250
      If search is randomised, number of parameter combos to try.
  max_ensemble_size : int or None, default = 50
      Maximum number of classifiers to retain. Will limit number of retained
      classifiers even if more than `max_ensemble_size` are within threshold.
  max_win_len_prop : int or float, default = 1
      Maximum window length as a proportion of the series length.
  min_window : int, default = 10
      Minimum window size.
  time_limit_in_minutes : int, default = 0
      Time contract to limit build time in minutes. Default of 0 means no limit.
  contract_max_n_parameter_samples : int, default=np.inf
      Max number of parameter combinations to consider when time_limit_in_minutes is
      set.
  save_train_predictions : bool, default=False
      Save the ensemble member train predictions in fit for use in _get_train_probs
      leave-one-out cross-validation.
  n_jobs : int, default = 1
      The number of jobs to run in parallel for both `fit` and `predict`.
      ``-1`` means using all processors.
  feature_selection: {"chi2", "none", "random"}, default: none
      Sets the feature selections strategy to be used. Chi2 reduces the number
      of words significantly and is thus much faster (preferred). Random also reduces
      the number significantly. None applies not feature selectiona and yields large
      bag of words, e.g. much memory may be needed.
  random_state : int or None, default=None
      Seed for random integer.
  
  Attributes
  ----------
  n_classes_ : int
      Number of classes. Extracted from the data.
  classes_ : list
      The classes labels.
  n_instances_ : int
      Number of instances. Extracted from the data.
  n_estimators_ : int
      The final number of classifiers used. Will be <= `max_ensemble_size` if
      `max_ensemble_size` has been specified.
  series_length_ : int
      Length of all series (assumed equal).
  estimators_ : list
     List of DecisionTree classifiers.
  weights_ :
      Weight of each classifier in the ensemble.
  
  See Also
  --------
  BOSSEnsemble, IndividualBOSS
  
  Notes
  -----
  For the Java version, see
  `TSML <https://github.com/uea-machine-learning/tsml/blob/master/src/main/java/
  tsml/classifiers/dictionary_based/cBOSS.java>`_.
  
  References
  ----------
  .. [1] Patrick Schäfer, "The BOSS is concerned with time series classification
     in the presence of noise", Data Mining and Knowledge Discovery, 29(6): 2015
     https://link.springer.com/article/10.1007/s10618-014-0377-7
  
  .. [2] Matthew Middlehurst, William Vickers and Anthony Bagnall
     "Scalable Dictionary Classifiers for Time Series Classification",
     in proc 20th International Conference on Intelligent Data Engineering
     and Automated Learning,LNCS, volume 11871
     https://link.springer.com/chapter/10.1007/978-3-030-33607-3_2
  
  Examples
  --------
  >>> from sktime.classification.dictionary_based import ContractableBOSS
  >>> from sktime.datasets import load_unit_test
  >>> X_train, y_train = load_unit_test(split="train", return_X_y=True)
  >>> X_test, y_test = load_unit_test(split="test", return_X_y=True)
  >>> clf = ContractableBOSS(
  ...     n_parameter_samples=10, max_ensemble_size=3
  ... ) # doctest: +SKIP
  >>> clf.fit(X_train, y_train) # doctest: +SKIP
  ContractableBOSS(...)
  >>> y_pred = clf.predict(X_test) # doctest: +SKIP
class_docstr_tok: ["Contractable","Bag","of","Symbolic","Fourier","Approximation","Symbols","(","cBOSS",")",".","Implementation","of","BOSS","Ensemble","from","Sch\u00e4fer","(","2015",")","with","refinements","described","in","Middlehurst",",","Vickers","and","Bagnall","(","2019",")",".","[","1",",","2","]","_","Overview",":","Input","``","n","''","series","of","length","``","m","''","and","cBOSS","randomly","samples","`","n_parameter_samples","`","parameter","sets",",","evaluating","each","with","LOOCV",".","It","then","retains","`","max_ensemble_size","`","classifiers","with","the","highest","accuracy","There","are","three","primary","parameters",":","-","alpha",":","alphabet","size","-","w",":","window","length","-","l",":","word","length",".","For","any","combination",",","a","single","BOSS","slides","a","window","length","``","w","''","along","the","series",".","The","``","w","''","length","window","is","shortened","to","an","``","l","''","length","word","by","taking","a","Fourier","transform","and","keeping","the","first","l\/2","complex","coefficients",".","These","``","l","''","coefficients","are","then","discretised","into","``","alpha","''","possible","values",",","to","form","a","word","length","``","l","''",".","A","histogram","of","words","for","each","series","is","formed","and","stored",".","Fit","involves","finding","``","n","''","histograms",".","Predict","uses","1","nearest","neighbor","with","a","bespoke","BOSS","distance","function",".","Parameters","--","--","--","--","--","n_parameter_samples",":","int",",","default","=","250","If","search","is","randomised",",","number","of","parameter","combos","to","try",".","max_ensemble_size",":","int","or","None",",","default","=","50","Maximum","number","of","classifiers","to","retain",".","Will","limit","number","of","retained","classifiers","even","if","more","than","`","max_ensemble_size","`","are","within","threshold",".","max_win_len_prop",":","int","or","float",",","default","=","1","Maximum","window","length","as","a","proportion","of","the","series","length",".","min_window",":","int",",","default","=","10","Minimum","window","size",".","time_limit_in_minutes",":","int",",","default","=","0","Time","contract","to","limit","build","time","in","minutes",".","Default","of","0","means","no","limit",".","contract_max_n_parameter_samples",":","int",",","default=np.inf","Max","number","of","parameter","combinations","to","consider","when","time_limit_in_minutes","is","set",".","save_train_predictions",":","bool",",","default=False","Save","the","ensemble","member","train","predictions","in","fit","for","use","in","_get_train_probs","leave-one-out","cross-validation",".","n_jobs",":","int",",","default","=","1","The","number","of","jobs","to","run","in","parallel","for","both","`","fit","`","and","`","predict","`",".","``","-1","``","means","using","all","processors",".","feature_selection",":","{","``","chi2","''",",","``","none","''",",","``","random","''","}",",","default",":","none","Sets","the","feature","selections","strategy","to","be","used",".","Chi2","reduces","the","number","of","words","significantly","and","is","thus","much","faster","(","preferred",")",".","Random","also","reduces","the","number","significantly",".","None","applies","not","feature","selectiona","and","yields","large","bag","of","words",",","e.g",".","much","memory","may","be","needed",".","random_state",":","int","or","None",",","default=None","Seed","for","random","integer",".","Attributes","--","--","--","--","--","n_classes_",":","int","Number","of","classes",".","Extracted","from","the","data",".","classes_",":","list","The","classes","labels",".","n_instances_",":","int","Number","of","instances",".","Extracted","from","the","data",".","n_estimators_",":","int","The","final","number","of","classifiers","used",".","Will","be","<","=","`","max_ensemble_size","`","if","`","max_ensemble_size","`","has","been","specified",".","series_length_",":","int","Length","of","all","series","(","assumed","equal",")",".","estimators_",":","list","List","of","DecisionTree","classifiers",".","weights_",":","Weight","of","each","classifier","in","the","ensemble",".","See","Also","--","--","--","--","BOSSEnsemble",",","IndividualBOSS","Notes","--","--","-","For","the","Java","version",",","see","`","TSML","<","https",":","\/\/github.com\/uea-machine-learning\/tsml\/blob\/master\/src\/main\/java\/","tsml\/classifiers\/dictionary_based\/cBOSS.java",">","`","_",".","References","--","--","--","--","--","..","[","1","]","Patrick","Sch\u00e4fer",",","``","The","BOSS","is","concerned","with","time","series","classification","in","the","presence","of","noise","''",",","Data","Mining","and","Knowledge","Discovery",",","29","(","6",")",":","2015","https",":","\/\/link.springer.com\/article\/10.1007\/s10618-014-0377-7","..","[","2","]","Matthew","Middlehurst",",","William","Vickers","and","Anthony","Bagnall","``","Scalable","Dictionary","Classifiers","for","Time","Series","Classification","''",",","in","proc","20th","International","Conference","on","Intelligent","Data","Engineering","and","Automated","Learning",",","LNCS",",","volume","11871","https",":","\/\/link.springer.com\/chapter\/10.1007\/978-3-030-33607-3_2","Examples","--","--","--","--",">",">",">","from","sktime.classification.dictionary_based","import","ContractableBOSS",">",">",">","from","sktime.datasets","import","load_unit_test",">",">",">","X_train",",","y_train","=","load_unit_test","(","split=","''","train","''",",","return_X_y=True",")",">",">",">","X_test",",","y_test","=","load_unit_test","(","split=","''","test","''",",","return_X_y=True",")",">",">",">","clf","=","ContractableBOSS","(","...","n_parameter_samples=10",",","max_ensemble_size=3","...",")","#","doctest",":","+SKIP",">",">",">","clf.fit","(","X_train",",","y_train",")","#","doctest",":","+SKIP","ContractableBOSS","(","...",")",">",">",">","y_pred","=","clf.predict","(","X_test",")","#","doctest",":","+SKIP"]
docstr: Fit a cBOSS ensemble on cases (X,y), where y is the target variable.
  
  Build an ensemble of BOSS classifiers from the training set (X,
  y), through randomising over the para space to make a fixed size
  ensemble of the best.
  
  Parameters
  ----------
  X : 3D np.array of shape = [n_instances, n_dimensions, series_length]
      The training data.
  y : array-like, shape = [n_instances]
      The class labels.
  
  Returns
  -------
  self :
      Reference to self.
  
  Notes
  -----
  Changes state by creating a fitted model that updates attributes
  ending in "_" and sets is_fitted flag to True.
docstr_tok: ["Fit","a","cBOSS","ensemble","on","cases","(","X",",","y",")",",","where","y","is","the","target","variable",".","Build","an","ensemble","of","BOSS","classifiers","from","the","training","set","(","X",",","y",")",",","through","randomising","over","the","para","space","to","make","a","fixed","size","ensemble","of","the","best",".","Parameters","--","--","--","--","--","X",":","3D","np.array","of","shape","=","[","n_instances",",","n_dimensions",",","series_length","]","The","training","data",".","y",":","array-like",",","shape","=","[","n_instances","]","The","class","labels",".","Returns","--","--","--","-","self",":","Reference","to","self",".","Notes","--","--","-","Changes","state","by","creating","a","fitted","model","that","updates","attributes","ending","in","``","_","''","and","sets","is_fitted","flag","to","True","."]
code: def _fit(self, X, y):
      """Fit a cBOSS ensemble on cases (X,y), where y is the target variable.
  
      Build an ensemble of BOSS classifiers from the training set (X,
      y), through randomising over the para space to make a fixed size
      ensemble of the best.
  
      Parameters
      ----------
      X : 3D np.array of shape = [n_instances, n_dimensions, series_length]
          The training data.
      y : array-like, shape = [n_instances]
          The class labels.
  
      Returns
      -------
      self :
          Reference to self.
  
      Notes
      -----
      Changes state by creating a fitted model that updates attributes
      ending in "_" and sets is_fitted flag to True.
      """
      time_limit = self.time_limit_in_minutes * 60
      self.n_instances_, _, self.series_length_ = X.shape
  
      self.estimators_ = []
      self.weights_ = []
  
      # Window length parameter space dependent on series length
      max_window_searches = self.series_length_ / 4
      max_window = int(self.series_length_ * self.max_win_len_prop)
      win_inc = int(
          (max_window - self.min_window) / max_window_searches
      )
      if win_inc < 1:
          win_inc = 1
      if self.min_window > max_window + 1:
          raise ValueError(
              f"Error in ContractableBOSS, min_window ="
              f"{self.min_window} is bigger"
              f" than max_window ={max_window}."
              f" Try set min_window to be smaller than series length in "
              f"the constructor, but the classifier may not work at "
              f"all with very short series"
          )
      possible_parameters = self._unique_parameters(max_window, win_inc)
      num_classifiers = 0
      start_time = time.time()
      train_time = 0
      subsample_size = int(self.n_instances_ * 0.7)
      lowest_acc = 1
      lowest_acc_idx = 0
  
      rng = check_random_state(self.random_state)
  
      if time_limit > 0:
          n_parameter_samples = 0
          contract_max_n_parameter_samples = (
              self.contract_max_n_parameter_samples
          )
      else:
          n_parameter_samples = self.n_parameter_samples
          contract_max_n_parameter_samples = np.inf
  
      while (
          (
              train_time < time_limit
              and num_classifiers < contract_max_n_parameter_samples
          )
          or num_classifiers < n_parameter_samples
      ) and len(possible_parameters) > 0:
          parameters = possible_parameters.pop(
              rng.randint(0, len(possible_parameters))
          )
  
          subsample = rng.choice(
              self.n_instances_, size=subsample_size, replace=False
          )
          X_subsample = X[subsample]
          y_subsample = y[subsample]
  
          boss = IndividualBOSS(
              *parameters,
              alphabet_size=self._alphabet_size,
              save_words=False,
              n_jobs=self.n_jobs,
              feature_selection=self.feature_selection,
              random_state=self.random_state,
          )
          boss.fit(X_subsample, y_subsample)
          boss._clean()
          boss._subsample = subsample
  
          boss._accuracy = self._individual_train_acc(
              boss,
              y_subsample,
              subsample_size,
              0
              if num_classifiers < self.max_ensemble_size
              else lowest_acc,
          )
          if boss._accuracy > 0:
              weight = math.pow(boss._accuracy, 4)
          else:
              weight = 0.000000001
  
          # Only keep the classifier, if its accuracy is non-zero
          if boss._accuracy > 0:
              if num_classifiers < self.max_ensemble_size:
                  if boss._accuracy < lowest_acc:
                      lowest_acc = boss._accuracy
                      lowest_acc_idx = num_classifiers
                  self.weights_.append(weight)
                  self.estimators_.append(boss)
              elif boss._accuracy > lowest_acc:
                  self.weights_[lowest_acc_idx] = weight
                  self.estimators_[lowest_acc_idx] = boss
                  (
                      lowest_acc,
                      lowest_acc_idx,
                  ) = self._worst_ensemble_acc()
  
              num_classifiers += 1
          train_time = time.time() - start_time
  
      self.n_estimators_ = len(self.estimators_)
      self._weight_sum = np.sum(self.weights_)
  
      return self
  
file_path: sktime/sktime/classification/dictionary_based/_cboss.py
imports: import math
  import time
  import numpy
  from sklearn.utils import check_random_state
  from sktime.classification.base import BaseClassifier
  from sktime.classification.dictionary_based import IndividualBOSS
  from sktime.classification.dictionary_based._boss import pairwise_distances
  from sktime.utils.validation.panel import check_X_y
label_desc: Use image node_id 2 for calling the ContractableBOSS obj's underlying member method code with example usage: obj._fit(X, y) and returns: self