Skip to content

Letting OneHotEncoder encode y? #5930

@hlin117

Description

@hlin117

I think the original use case for OneHotEncoders were to encode features, but it would be nice if they were able to encode y's as well. The current functionality is as follows:

>>> from sklearn.preprocessing import OneHotEncoder
>>> y = [0, 1, 1, 0]
>>> transformed = OneHotEncoder().fit_transform(y).toarray()
/usr/local/lib/python2.7/site-packages/sklearn/utils/validation.py:386: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
  DeprecationWarning)
>>> transformed
array([[ 1.,  1.,  1.,  1.]])

Right now it's interpreting y as a single sample; the desired behavior is by letting y = np.array([0, 1, 1, 0]).reshape(-1, 1), and then running the OneHotEncoder.

What do you guys think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationEasyWell-defined and straightforward way to resolve

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions