Skip to content

Diff between PR #9216 and #8652#1

Merged
ruxandraburtica merged 1 commit intoordinal-encoderfrom
ordinal-encoder-updates
Jun 25, 2017
Merged

Diff between PR #9216 and #8652#1
ruxandraburtica merged 1 commit intoordinal-encoderfrom
ordinal-encoder-updates

Conversation

@ruxandraburtica
Copy link
Copy Markdown
Collaborator

Reference Issue

scikit-learn#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 ruxandraburtica merged commit 19d33fb into ordinal-encoder Jun 25, 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