Toggle Menu
Prev Up Next

scikit-learn 1.3.2
Other versions

Please cite us if you use the software.

# `sklearn.preprocessing`.add_dummy_feature

sklearn.preprocessing.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} of shape (n_samples, n_features)

      Data.

    value float

      Value to use for the dummy feature.

  Returns:
    X{ndarray, sparse matrix} of 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.]])