class_docstr: Learning Time-Series Shapelets model.
  
  
  Learning Time-Series Shapelets was originally presented in [1]_.
  
  From an input (possibly multidimensional) time series :math:`x` and a set
  of shapelets :math:`\{s_i\}_i`, the :math:`i`-th coordinate of the Shapelet
  transform is computed as:
  
  .. math::
  
      ST(x, s_i) = \min_t \sum_{\delta_t}
          \left\|x(t+\delta_t) - s_i(\delta_t)\right\|_2^2
  
  The Shapelet model consists in a logistic regression layer on top of this
  transform. Shapelet coefficients as well as logistic regression weights are
  optimized by gradient descent on a L2-penalized cross-entropy loss.
  
  Parameters
  ----------
  n_shapelets_per_size: dict (default: None)
      Dictionary giving, for each shapelet size (key),
      the number of such shapelets to be trained (value). 
      If None, `grabocka_params_to_shapelet_size_dict` is used and the
      size used to compute is that of the shortest time series passed at fit 
      time.
      
  max_iter: int (default: 10,000)
      Number of training epochs.
  
      .. versionchanged:: 0.3
          default value for max_iter is set to 10,000 instead of 100
  
  batch_size: int (default: 256)
      Batch size to be used.
  
  verbose: {0, 1, 2} (default: 0)
      `keras` verbose level.
  
  optimizer: str or keras.optimizers.Optimizer (default: "sgd")
      `keras` optimizer to use for training.
  
  weight_regularizer: float or None (default: 0.)
      Strength of the L2 regularizer to use for training the classification
      (softmax) layer. If 0, no regularization is performed.
  
  shapelet_length: float (default: 0.15)
      The length of the shapelets, expressed as a fraction of the time 
      series length.
      Used only if `n_shapelets_per_size` is None.
  
  total_lengths: int (default: 3)
      The number of different shapelet lengths. Will extract shapelets of
      length i * shapelet_length for i in [1, total_lengths]
      Used only if `n_shapelets_per_size` is None.
      
  max_size: int or None (default: None)
      Maximum size for time series to be fed to the model. If None, it is 
      set to the size (number of timestamps) of the training time series.
      
  scale: bool (default: False)
      Whether input data should be scaled for each feature of each time 
      series to lie in the [0-1] interval.
      Default for this parameter is set to `False` in version 0.4 to ensure
      backward compatibility, but is likely to change in a future version.        
  
  random_state : int or None, optional (default: None)
      The seed of the pseudo random number generator to use when shuffling
      the data.  If int, random_state is the seed used by the random number
      generator; If None, the random number generator is the RandomState
      instance used by `np.random`.
  
  Attributes
  ----------
  shapelets_ : numpy.ndarray of objects, each object being a time series
      Set of time-series shapelets.
  
  shapelets_as_time_series_ : numpy.ndarray of shape (n_shapelets, sz_shp, d) where `sz_shp` is the maximum of all shapelet sizes
      Set of time-series shapelets formatted as a ``tslearn`` time series
      dataset.
  
  transformer_model_ : keras.Model
      Transforms an input dataset of timeseries into distances to the
      learned shapelets.
  
  locator_model_ : keras.Model
      Returns the indices where each of the shapelets can be found (minimal
      distance) within each of the timeseries of the input dataset.
  
  model_ : keras.Model
      Directly predicts the class probabilities for the input timeseries.
  
  history_ : dict
      Dictionary of losses and metrics recorded during fit.
  
  Examples
  --------
  >>> from tslearn.generators import random_walk_blobs
  >>> X, y = random_walk_blobs(n_ts_per_blob=10, sz=16, d=2, n_blobs=3)
  >>> clf = LearningShapelets(n_shapelets_per_size={4: 5}, 
  ...                         max_iter=1, verbose=0)
  >>> clf.fit(X, y).shapelets_.shape
  (5,)
  >>> clf.shapelets_[0].shape
  (4, 2)
  >>> clf.predict(X).shape
  (30,)
  >>> clf.predict_proba(X).shape
  (30, 3)
  >>> clf.transform(X).shape
  (30, 5)
  
  References
  ----------
  .. [1] J. Grabocka et al. Learning Time-Series Shapelets. SIGKDD 2014.
class_docstr_tok: ["Learning","Time-Series","Shapelets","model",".","Learning","Time-Series","Shapelets","was","originally","presented","in","[","1","]","_",".","From","an","input","(","possibly","multidimensional",")","time","series",":","math",":","`","x","`","and","a","set","of","shapelets",":","math",":","`","\\","{","s_i\\","}","_i","`",",","the",":","math",":","`","i","`","-th","coordinate","of","the","Shapelet","transform","is","computed","as",":","..","math",":",":","ST","(","x",",","s_i",")","=","\\min_t","\\sum_","{","\\delta_t","}","\\left\\|x","(","t+\\delta_t",")","-","s_i","(","\\delta_t",")","\\right\\|_2^2","The","Shapelet","model","consists","in","a","logistic","regression","layer","on","top","of","this","transform",".","Shapelet","coefficients","as","well","as","logistic","regression","weights","are","optimized","by","gradient","descent","on","a","L2-penalized","cross-entropy","loss",".","Parameters","--","--","--","--","--","n_shapelets_per_size",":","dict","(","default",":","None",")","Dictionary","giving",",","for","each","shapelet","size","(","key",")",",","the","number","of","such","shapelets","to","be","trained","(","value",")",".","If","None",",","`","grabocka_params_to_shapelet_size_dict","`","is","used","and","the","size","used","to","compute","is","that","of","the","shortest","time","series","passed","at","fit","time",".","max_iter",":","int","(","default",":","10,000",")","Number","of","training","epochs",".","..","versionchanged",":",":","0.3","default","value","for","max_iter","is","set","to","10,000","instead","of","100","batch_size",":","int","(","default",":","256",")","Batch","size","to","be","used",".","verbose",":","{","0",",","1",",","2","}","(","default",":","0",")","`","keras","`","verbose","level",".","optimizer",":","str","or","keras.optimizers.Optimizer","(","default",":","``","sgd","''",")","`","keras","`","optimizer","to","use","for","training",".","weight_regularizer",":","float","or","None","(","default",":","0",".",")","Strength","of","the","L2","regularizer","to","use","for","training","the","classification","(","softmax",")","layer",".","If","0",",","no","regularization","is","performed",".","shapelet_length",":","float","(","default",":","0.15",")","The","length","of","the","shapelets",",","expressed","as","a","fraction","of","the","time","series","length",".","Used","only","if","`","n_shapelets_per_size","`","is","None",".","total_lengths",":","int","(","default",":","3",")","The","number","of","different","shapelet","lengths",".","Will","extract","shapelets","of","length","i","*","shapelet_length","for","i","in","[","1",",","total_lengths","]","Used","only","if","`","n_shapelets_per_size","`","is","None",".","max_size",":","int","or","None","(","default",":","None",")","Maximum","size","for","time","series","to","be","fed","to","the","model",".","If","None",",","it","is","set","to","the","size","(","number","of","timestamps",")","of","the","training","time","series",".","scale",":","bool","(","default",":","False",")","Whether","input","data","should","be","scaled","for","each","feature","of","each","time","series","to","lie","in","the","[","0-1","]","interval",".","Default","for","this","parameter","is","set","to","`","False","`","in","version","0.4","to","ensure","backward","compatibility",",","but","is","likely","to","change","in","a","future","version",".","random_state",":","int","or","None",",","optional","(","default",":","None",")","The","seed","of","the","pseudo","random","number","generator","to","use","when","shuffling","the","data",".","If","int",",","random_state","is","the","seed","used","by","the","random","number","generator",";","If","None",",","the","random","number","generator","is","the","RandomState","instance","used","by","`","np.random","`",".","Attributes","--","--","--","--","--","shapelets_",":","numpy.ndarray","of","objects",",","each","object","being","a","time","series","Set","of","time-series","shapelets",".","shapelets_as_time_series_",":","numpy.ndarray","of","shape","(","n_shapelets",",","sz_shp",",","d",")","where","`","sz_shp","`","is","the","maximum","of","all","shapelet","sizes","Set","of","time-series","shapelets","formatted","as","a","``","tslearn","``","time","series","dataset",".","transformer_model_",":","keras.Model","Transforms","an","input","dataset","of","timeseries","into","distances","to","the","learned","shapelets",".","locator_model_",":","keras.Model","Returns","the","indices","where","each","of","the","shapelets","can","be","found","(","minimal","distance",")","within","each","of","the","timeseries","of","the","input","dataset",".","model_",":","keras.Model","Directly","predicts","the","class","probabilities","for","the","input","timeseries",".","history_",":","dict","Dictionary","of","losses","and","metrics","recorded","during","fit",".","Examples","--","--","--","--",">",">",">","from","tslearn.generators","import","random_walk_blobs",">",">",">","X",",","y","=","random_walk_blobs","(","n_ts_per_blob=10",",","sz=16",",","d=2",",","n_blobs=3",")",">",">",">","clf","=","LearningShapelets","(","n_shapelets_per_size=","{","4",":","5","}",",","...","max_iter=1",",","verbose=0",")",">",">",">","clf.fit","(","X",",","y",")",".shapelets_.shape","(","5",",",")",">",">",">","clf.shapelets_","[","0","]",".shape","(","4",",","2",")",">",">",">","clf.predict","(","X",")",".shape","(","30",",",")",">",">",">","clf.predict_proba","(","X",")",".shape","(","30",",","3",")",">",">",">","clf.transform","(","X",")",".shape","(","30",",","5",")","References","--","--","--","--","--","..","[","1","]","J.","Grabocka","et","al",".","Learning","Time-Series","Shapelets",".","SIGKDD","2014","."]
code: def _preprocess_series(self, X):
      if self.scale:
          X = TimeSeriesScalerMinMax().fit_transform(X)
      else:
          X = to_time_series_dataset(X)
      if self.max_size is not None and self.max_size != X.shape[1]:
          if X.shape[1] > self.max_size:
              raise ValueError(
                  "Cannot feed model with series of length {} "
                  "max_size is {}".format(X.shape[1], self.max_size)
              )
          X_ = numpy.zeros((X.shape[0], self.max_size, X.shape[2]))
          X_[:, : X.shape[1]] = X
          X_[:, X.shape[1] :] = numpy.nan
          return X_
      else:
          return X
  
imports: from tensorflow.keras.models import Model, model_from_json
  from tensorflow.keras.layers import InputSpec, Dense, Conv1D, Layer, Input, concatenate, add
  from tensorflow.keras.metrics import categorical_accuracy, categorical_crossentropy, binary_accuracy, binary_crossentropy
  from tensorflow.keras.utils import to_categorical
  from sklearn.base import ClassifierMixin, TransformerMixin
  from sklearn.utils import check_array, check_X_y
  from sklearn.utils.validation import check_is_fitted
  from sklearn.utils.multiclass import unique_labels
  from tensorflow.keras.regularizers import l2
  from tensorflow.keras.initializers import Initializer
  import tensorflow.keras.backend
  import numpy
  import tensorflow
  import warnings
  from ..utils import to_time_series_dataset, check_dims, ts_size
  from ..bases import BaseModelPackage, TimeSeriesBaseEstimator
  from ..clustering import TimeSeriesKMeans
  from ..preprocessing import TimeSeriesScalerMinMax
label_desc: Use image node_id 11 for calling the LearningShapelets obj's underlying member method code with example usage: obj._preprocess_series(X) and returns: X_, X