Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MRG+1] Docs: refer users to the other encoders to do one hot encoding for labels. #7315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sklearn/preprocessing/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,9 @@ class OneHotEncoder(BaseEstimator, TransformerMixin):
This encoding is needed for feeding categorical data to many scikit-learn
estimators, notably linear models and SVMs with the standard kernels.

Note: a one-hot encoding of y labels should use a LabelBinarizer
instead.

Read more in the :ref:`User Guide <preprocessing_categorical_features>`.

Parameters
Expand Down Expand Up @@ -1810,6 +1813,13 @@ class OneHotEncoder(BaseEstimator, TransformerMixin):
dictionary items (also handles string-valued features).
sklearn.feature_extraction.FeatureHasher : performs an approximate one-hot
encoding of dictionary items or strings.
sklearn.preprocessing.LabelBinarizer : binarizes labels in a one-vs-all
fashion.
sklearn.preprocessing.MultiLabelBinarizer : transforms between iterable of
iterables and a multilabel format, e.g. a (samples x classes) binary
matrix indicating the presence of a class label.
sklearn.preprocessing.LabelEncoder : encodes labels with values between 0
and n_classes-1.
"""
def __init__(self, n_values="auto", categorical_features="all",
dtype=np.float64, sparse=True, handle_unknown='error'):
Expand Down
11 changes: 11 additions & 0 deletions sklearn/preprocessing/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class LabelEncoder(BaseEstimator, TransformerMixin):
>>> list(le.inverse_transform([2, 2, 1]))
['tokyo', 'tokyo', 'paris']

See also
--------
sklearn.preprocessing.OneHotEncoder : encode categorical integer features
using a one-hot aka one-of-K scheme.
"""

def fit(self, y):
Expand Down Expand Up @@ -257,6 +261,8 @@ class LabelBinarizer(BaseEstimator, TransformerMixin):
--------
label_binarize : function to perform the transform operation of
LabelBinarizer with fixed classes.
sklearn.preprocessing.OneHotEncoder : encode categorical integer features
using a one-hot aka one-of-K scheme.
"""

def __init__(self, neg_label=0, pos_label=1, sparse_output=False):
Expand Down Expand Up @@ -648,6 +654,7 @@ class MultiLabelBinarizer(BaseEstimator, TransformerMixin):

Examples
--------
>>> from sklearn.preprocessing import MultiLabelBinarizer
>>> mlb = MultiLabelBinarizer()
>>> mlb.fit_transform([(1, 2), (3,)])
array([[1, 1, 0],
Expand All @@ -661,6 +668,10 @@ class MultiLabelBinarizer(BaseEstimator, TransformerMixin):
>>> list(mlb.classes_)
['comedy', 'sci-fi', 'thriller']

See also
--------
sklearn.preprocessing.OneHotEncoder : encode categorical integer features
using a one-hot aka one-of-K scheme.
"""
def __init__(self, classes=None, sparse_output=False):
self.classes = classes
Expand Down