parameters: (X, value=1.0)
docstring: Augment dataset with an additional dummy feature.
  
      This is useful for fitting an intercept term with implementations which
      cannot otherwise fit it directly.
  
      Parameters
      ----------
      X : {array-like, sparse matrix}, shape [n_samples, n_features]
          Data.
  
      value : float
          Value to use for the dummy feature.
  
      Returns
      -------
  
      X : {array, sparse matrix}, shape [n_samples, n_features + 1]
          Same data with dummy feature added as first column.
  
      Examples
      --------
  
      >>> from sklearn.preprocessing import add_dummy_feature
      >>> add_dummy_feature([[0, 1], [1, 0]])
      array([[1., 0., 1.],
             [1., 1., 0.]])
docstring_summary: Augment dataset with an additional dummy feature.
docstring_tokens: Augment dataset with an additional dummy feature .
function: def add_dummy_feature(X, value=1.0):
      """Augment dataset with an additional dummy feature.
  
      This is useful for fitting an intercept term with implementations which
      cannot otherwise fit it directly.
  
      Parameters
      ----------
      X : {array-like, sparse matrix}, shape [n_samples, n_features]
          Data.
  
      value : float
          Value to use for the dummy feature.
  
      Returns
      -------
  
      X : {array, sparse matrix}, shape [n_samples, n_features + 1]
          Same data with dummy feature added as first column.
  
      Examples
      --------
  
      >>> from sklearn.preprocessing import add_dummy_feature
      >>> add_dummy_feature([[0, 1], [1, 0]])
      array([[1., 0., 1.],
             [1., 1., 0.]])
      """
      X = check_array(X, accept_sparse=['csc', 'csr', 'coo'], dtype=FLOAT_DTYPES)
      n_samples, n_features = X.shape
      shape = (n_samples, n_features + 1)
      if sparse.issparse(X):
          if sparse.isspmatrix_coo(X):
              # Shift columns to the right.
              col = X.col + 1
              # Column indices of dummy feature are 0 everywhere.
              col = np.concatenate((np.zeros(n_samples), col))
              # Row indices of dummy feature are 0, ..., n_samples-1.
              row = np.concatenate((np.arange(n_samples), X.row))
              # Prepend the dummy feature n_samples times.
              data = np.concatenate((np.full(n_samples, value), X.data))
              return sparse.coo_matrix((data, (row, col)), shape)
          elif sparse.isspmatrix_csc(X):
              # Shift index pointers since we need to add n_samples elements.
              indptr = X.indptr + n_samples
              # indptr[0] must be 0.
              indptr = np.concatenate((np.array([0]), indptr))
              # Row indices of dummy feature are 0, ..., n_samples-1.
              indices = np.concatenate((np.arange(n_samples), X.indices))
              # Prepend the dummy feature n_samples times.
              data = np.concatenate((np.full(n_samples, value), X.data))
              return sparse.csc_matrix((data, indices, indptr), shape)
          else:
              klass = X.__class__
              return klass(add_dummy_feature(X.tocoo(), value))
      else:
          return np.hstack((np.full((n_samples, 1), value), X))
function_tokens: def add_dummy_feature ( X , value = 1.0 ) : X = check_array ( X , accept_sparse = [ 'csc' , 'csr' , 'coo' ] , dtype = FLOAT_DTYPES ) n_samples , n_features = X . shape shape = ( n_samples , n_features + 1 ) if sparse . issparse ( X ) : if sparse . isspmatrix_coo ( X ) : # Shift columns to the right. col = X . col + 1 # Column indices of dummy feature are 0 everywhere. col = np . concatenate ( ( np . zeros ( n_samples ) , col ) ) # Row indices of dummy feature are 0, ..., n_samples-1. row = np . concatenate ( ( np . arange ( n_samples ) , X . row ) ) # Prepend the dummy feature n_samples times. data = np . concatenate ( ( np . full ( n_samples , value ) , X . data ) ) return sparse . coo_matrix ( ( data , ( row , col ) ) , shape ) elif sparse . isspmatrix_csc ( X ) : # Shift index pointers since we need to add n_samples elements. indptr = X . indptr + n_samples # indptr[0] must be 0. indptr = np . concatenate ( ( np . array ( [ 0 ] ) , indptr ) ) # Row indices of dummy feature are 0, ..., n_samples-1. indices = np . concatenate ( ( np . arange ( n_samples ) , X . indices ) ) # Prepend the dummy feature n_samples times. data = np . concatenate ( ( np . full ( n_samples , value ) , X . data ) ) return sparse . csc_matrix ( ( data , indices , indptr ) , shape ) else : klass = X . __class__ return klass ( add_dummy_feature ( X . tocoo ( ) , value ) ) else : return np . hstack ( ( np . full ( ( n_samples , 1 ) , value ) , X ) )