Skip to content

[WIP] UnaryEncoder#9216

Closed
ruxandraburtica wants to merge 7 commits intoscikit-learn:masterfrom
ruxandraburtica:unary-encoder
Closed

[WIP] UnaryEncoder#9216
ruxandraburtica wants to merge 7 commits intoscikit-learn:masterfrom
ruxandraburtica:unary-encoder

Conversation

@ruxandraburtica
Copy link
Copy Markdown

@ruxandraburtica ruxandraburtica commented Jun 24, 2017

Implements #8628


What does this implement/fix? Explain your changes.

This implements UnaryEncoder, which is a more informative encoding than one-hot for ordinal features. Implemented a new class UnaryEncoder whose interface is same as OneHotEncoder class.

Any other comments?

Logic: For k values 0, ..., k - 1 of the ordinal feature x, this creates k - 1 binary features such that the ith is active if x > j (for j = 0, ... i)

Working Example

>>> from sklearn.preprocessing import UnaryEncoder
>>> enc = UnaryEncoder()
>>> enc.fit([[0, 0, 3], [1, 1, 0], [0, 2, 1], [1, 0, 2]])  
UnaryEncoder(dtype=<type 'numpy.float64'>, handle_unknown='error',
        n_values='auto', ordinal_features='all', sparse=True)
>>> 
>>> enc.n_values_
array([2, 3, 4])
>>> 
>>> enc.feature_indices_
array([0, 1, 3, 6])
>>> 
>>> enc.active_features_
array([0, 1, 2, 3, 4, 5])
>>>
>>> enc.transform([[0, 1, 1]]).toarray()
array([[ 0.,  1.,  0.,  1.,  0.,  0.]])
>>> UnaryEncoder(3).fit_transform([[0], [1], [2]]).toarray()
array([[ 0.,  0.],
       [ 1.,  0.],
       [ 1.,  1.]])

ruxandraburtica added a commit to arjunjauhari/scikit-learn that referenced this pull request Jun 25, 2017
ruxandraburtica added a commit to arjunjauhari/scikit-learn that referenced this pull request Jun 25, 2017
@ruxandraburtica
Copy link
Copy Markdown
Author

Closing this, since diff was merged in #8652

arjunjauhari pushed a commit to arjunjauhari/scikit-learn that referenced this pull request Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant