class_docstr: Encode categorical integer features using a one-hot aka one-of-K scheme.
  
  The input to this transformer should be a matrix of integers, denoting
  the values taken on by categorical (discrete) features. The output will be
  a sparse matrix were each column corresponds to one possible value of one
  feature. It is assumed that input features take on values in the range
  [0, n_values).
  
  This encoding is needed for feeding categorical data to many scikit-learn
  estimators, notably linear models and SVMs with the standard kernels.
  
  Parameters
  ----------
  
  categorical_features: "all" or array of indices or mask
      Specify what features are treated as categorical.
  
      - 'all': All features are treated as categorical.
      - 'auto' (default): Select only features that have less than 10 unique values.
      - array of indices: Array of categorical feature indices.
      - mask: Array of length n_features and with dtype=bool.
  
      Non-categorical features are always stacked to the right of the matrix.
  
  dtype : number type, default=np.float64
      Desired dtype of output.
  
  sparse : boolean, default=True
      Will return sparse matrix if set True else will return an array.
  
  threshold : int, default=10
      Maximum number of unique values per feature to consider the feature
      to be categorical when categorical_features is 'auto'.
  
  minimum_fraction : float, default=None
      Minimum fraction of unique values in a feature to consider the feature
      to be categorical.
  
  Attributes
  ----------
  `active_features_` : array
      Indices for active features, meaning values that actually occur
      in the training set. Only available when n_values is ``'auto'``.
  
  `feature_indices_` : array of shape (n_features,)
      Indices to feature ranges.
      Feature ``i`` in the original data is mapped to features
      from ``feature_indices_[i]`` to ``feature_indices_[i+1]``
      (and then potentially masked by `active_features_` afterwards)
  
  `n_values_` : array of shape (n_features,)
      Maximum number of values per feature.
  
  Examples
  --------
  Given a dataset with three features and two samples, we let the encoder
  find the maximum value per feature and transform the data to a binary
  one-hot encoding.
  
  >>> from sklearn.preprocessing import OneHotEncoder
  >>> enc = OneHotEncoder()
  >>> enc.fit([[0, 0, 3], [1, 1, 0], [0, 2, 1], [1, 0, 2]])  # doctest: +ELLIPSIS
  OneHotEncoder(categorical_features='all', dtype=<... 'float'>,
         sparse=True, minimum_fraction=None)
  >>> enc.n_values_
  array([2, 3, 4])
  >>> enc.feature_indices_
  array([0, 2, 5, 9])
  >>> enc.transform([[0, 1, 1]]).toarray()
  array([[ 1.,  0.,  0.,  1.,  0.,  0.,  1.,  0.,  0.]])
  
  See also
  --------
  sklearn.feature_extraction.DictVectorizer : performs a one-hot encoding of
    dictionary items (also handles string-valued features).
  sklearn.feature_extraction.FeatureHasher : performs an approximate one-hot
    encoding of dictionary items or strings.
class_docstr_tok: ["Encode","categorical","integer","features","using","a","one-hot","aka","one-of-K","scheme",".","The","input","to","this","transformer","should","be","a","matrix","of","integers",",","denoting","the","values","taken","on","by","categorical","(","discrete",")","features",".","The","output","will","be","a","sparse","matrix","were","each","column","corresponds","to","one","possible","value","of","one","feature",".","It","is","assumed","that","input","features","take","on","values","in","the","range","[","0",",","n_values",")",".","This","encoding","is","needed","for","feeding","categorical","data","to","many","scikit-learn","estimators",",","notably","linear","models","and","SVMs","with","the","standard","kernels",".","Parameters","--","--","--","--","--","categorical_features",":","``","all","''","or","array","of","indices","or","mask","Specify","what","features","are","treated","as","categorical",".","-","'all","'",":","All","features","are","treated","as","categorical",".","-","'auto","'","(","default",")",":","Select","only","features","that","have","less","than","10","unique","values",".","-","array","of","indices",":","Array","of","categorical","feature","indices",".","-","mask",":","Array","of","length","n_features","and","with","dtype=bool",".","Non-categorical","features","are","always","stacked","to","the","right","of","the","matrix",".","dtype",":","number","type",",","default=np.float64","Desired","dtype","of","output",".","sparse",":","boolean",",","default=True","Will","return","sparse","matrix","if","set","True","else","will","return","an","array",".","threshold",":","int",",","default=10","Maximum","number","of","unique","values","per","feature","to","consider","the","feature","to","be","categorical","when","categorical_features","is","'auto","'",".","minimum_fraction",":","float",",","default=None","Minimum","fraction","of","unique","values","in","a","feature","to","consider","the","feature","to","be","categorical",".","Attributes","--","--","--","--","--","`","active_features_","`",":","array","Indices","for","active","features",",","meaning","values","that","actually","occur","in","the","training","set",".","Only","available","when","n_values","is","``","'auto","'","``",".","`","feature_indices_","`",":","array","of","shape","(","n_features",",",")","Indices","to","feature","ranges",".","Feature","``","i","``","in","the","original","data","is","mapped","to","features","from","``","feature_indices_","[","i","]","``","to","``","feature_indices_","[","i+1","]","``","(","and","then","potentially","masked","by","`","active_features_","`","afterwards",")","`","n_values_","`",":","array","of","shape","(","n_features",",",")","Maximum","number","of","values","per","feature",".","Examples","--","--","--","--","Given","a","dataset","with","three","features","and","two","samples",",","we","let","the","encoder","find","the","maximum","value","per","feature","and","transform","the","data","to","a","binary","one-hot","encoding",".",">",">",">","from","sklearn.preprocessing","import","OneHotEncoder",">",">",">","enc","=","OneHotEncoder","(",")",">",">",">","enc.fit","(","[","[","0",",","0",",","3","]",",","[","1",",","1",",","0","]",",","[","0",",","2",",","1","]",",","[","1",",","0",",","2","]","]",")","#","doctest",":","+ELLIPSIS","OneHotEncoder","(","categorical_features='all","'",",","dtype=","<","...","'float","'",">",",","sparse=True",",","minimum_fraction=None",")",">",">",">","enc.n_values_","array","(","[","2",",","3",",","4","]",")",">",">",">","enc.feature_indices_","array","(","[","0",",","2",",","5",",","9","]",")",">",">",">","enc.transform","(","[","[","0",",","1",",","1","]","]",")",".toarray","(",")","array","(","[","[","1.",",","0.",",","0.",",","1.",",","0.",",","0.",",","1.",",","0.",",","0",".","]","]",")","See","also","--","--","--","--","sklearn.feature_extraction.DictVectorizer",":","performs","a","one-hot","encoding","of","dictionary","items","(","also","handles","string-valued","features",")",".","sklearn.feature_extraction.FeatureHasher",":","performs","an","approximate","one-hot","encoding","of","dictionary","items","or","strings","."]
docstr: Assume X contains only categorical features.
  
  Parameters
  ----------
  X : array-like or sparse matrix, shape=(n_samples, n_features)
      Dense array or sparse matrix.
docstr_tok: ["Assume","X","contains","only","categorical","features",".","Parameters","--","--","--","--","--","X",":","array-like","or","sparse","matrix",",","shape=","(","n_samples",",","n_features",")","Dense","array","or","sparse","matrix","."]
code: def _fit_transform(self, X):
      """Assume X contains only categorical features.
  
      Parameters
      ----------
      X : array-like or sparse matrix, shape=(n_samples, n_features)
          Dense array or sparse matrix.
      """
      X = self._matrix_adjust(X)
  
      X = check_array(
          X, accept_sparse="csc", force_all_finite=False, dtype=int
      )
  
      if X.min() < 0:
          raise ValueError(
              "X needs to contain only non-negative integers."
          )
  
      n_samples, n_features = X.shape
  
      # Remember which values should not be replaced by the value 'other'
      if self.minimum_fraction is not None:
          do_not_replace_by_other = []
          for column in range(X.shape[1]):
              do_not_replace_by_other.append(list())
  
              if sparse.issparse(X):
                  indptr_start = X.indptr[column]
                  indptr_end = X.indptr[column + 1]
                  unique = np.unique(X.data[indptr_start:indptr_end])
                  colsize = indptr_end - indptr_start
              else:
                  unique = np.unique(X[:, column])
                  colsize = X.shape[0]
  
              for unique_value in unique:
                  if np.isfinite(unique_value):
                      if sparse.issparse(X):
                          indptr_start = X.indptr[column]
                          indptr_end = X.indptr[column + 1]
                          count = np.nansum(
                              unique_value
                              == X.data[indptr_start:indptr_end]
                          )
                      else:
                          count = np.nansum(
                              unique_value == X[:, column]
                          )
                  else:
                      if sparse.issparse(X):
                          indptr_start = X.indptr[column]
                          indptr_end = X.indptr[column + 1]
                          count = np.nansum(
                              ~np.isfinite(
                                  X.data[indptr_start:indptr_end]
                              )
                          )
                      else:
                          count = np.nansum(~np.isfinite(X[:, column]))
  
                  fraction = float(count) / colsize
                  if fraction >= self.minimum_fraction:
                      do_not_replace_by_other[-1].append(unique_value)
  
              for unique_value in unique:
                  if unique_value not in do_not_replace_by_other[-1]:
                      if sparse.issparse(X):
                          indptr_start = X.indptr[column]
                          indptr_end = X.indptr[column + 1]
                          X.data[indptr_start:indptr_end][
                              X.data[indptr_start:indptr_end]
                              == unique_value
                          ] = SPARSE_ENCODINGS["OTHER"]
                      else:
                          X[:, column][
                              X[:, column] == unique_value
                          ] = SPARSE_ENCODINGS["OTHER"]
  
          self.do_not_replace_by_other_ = do_not_replace_by_other
  
      if sparse.issparse(X):
          n_values = X.max(axis=0).toarray().flatten() + len(
              SPARSE_ENCODINGS
          )
      else:
          n_values = np.max(X, axis=0) + len(SPARSE_ENCODINGS)
  
      self.n_values_ = n_values
      n_values = np.hstack([[0], n_values])
      indices = np.cumsum(n_values)
      self.feature_indices_ = indices
  
      if sparse.issparse(X):
          row_indices = X.indices
          column_indices = []
          for i in range(len(X.indptr) - 1):
              nbr = X.indptr[i + 1] - X.indptr[i]
              column_indices_ = [indices[i]] * nbr
              column_indices_ += X.data[X.indptr[i] : X.indptr[i + 1]]
              column_indices.extend(column_indices_)
          data = np.ones(X.data.size)
      else:
          column_indices = (X + indices[:-1]).ravel()
          row_indices = np.repeat(
              np.arange(n_samples, dtype=np.int32), n_features
          )
          data = np.ones(n_samples * n_features)
  
      out = sparse.coo_matrix(
          (data, (row_indices, column_indices)),
          shape=(n_samples, indices[-1]),
          dtype=self.dtype,
      ).tocsc()
  
      mask = np.array(out.sum(axis=0)).ravel() != 0
      active_features = np.where(mask)[0]
      out = out[:, active_features]
      self.active_features_ = active_features
      return out.tocsr() if self.sparse else out.toarray()
  
file_path: tpot/tpot/builtins/one_hot_encoder.py
imports: import numpy
  from scipy import sparse
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.utils import check_array
label_desc: Use image node_id 4 for calling the OneHotEncoder obj's underlying member method code with example usage: obj._fit_transform(X) and returns: unknown