From 8fd7a05e9519b3231b752bf335b358f9d6dd307c Mon Sep 17 00:00:00 2001 From: gloriamacia Date: Sat, 3 Jul 2021 19:32:07 +0200 Subject: [PATCH 1/2] fix LabelEncoder DOCS --- maint_tools/test_docstrings.py | 1 - sklearn/preprocessing/_label.py | 16 ++++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/maint_tools/test_docstrings.py b/maint_tools/test_docstrings.py index 9b23b1789aeb4..412e68b82eaab 100644 --- a/maint_tools/test_docstrings.py +++ b/maint_tools/test_docstrings.py @@ -72,7 +72,6 @@ "KernelPCA", "KernelRidge", "LabelBinarizer", - "LabelEncoder", "LabelPropagation", "LabelSpreading", "Lars", diff --git a/sklearn/preprocessing/_label.py b/sklearn/preprocessing/_label.py index 224eeda00d124..f1547e03aeeb6 100644 --- a/sklearn/preprocessing/_label.py +++ b/sklearn/preprocessing/_label.py @@ -49,6 +49,12 @@ class LabelEncoder(TransformerMixin, BaseEstimator): classes_ : ndarray of shape (n_classes,) Holds the label for each class. + See Also + -------- + OrdinalEncoder : Encode categorical features using an ordinal encoding + scheme. + OneHotEncoder : Encode categorical features as a one-hot numeric array. + Examples -------- `LabelEncoder` can be used to normalize labels. @@ -76,12 +82,6 @@ class LabelEncoder(TransformerMixin, BaseEstimator): array([2, 2, 1]...) >>> list(le.inverse_transform([2, 2, 1])) ['tokyo', 'tokyo', 'paris'] - - See Also - -------- - OrdinalEncoder : Encode categorical features using an ordinal encoding - scheme. - OneHotEncoder : Encode categorical features as a one-hot numeric array. """ def fit(self, y): @@ -95,6 +95,7 @@ def fit(self, y): Returns ------- self : returns an instance of self. + Fitted label encoder. """ y = column_or_1d(y, warn=True) self.classes_ = _unique(y) @@ -111,6 +112,7 @@ def fit_transform(self, y): Returns ------- y : array-like of shape (n_samples,) + Encoded labels. """ y = column_or_1d(y, warn=True) self.classes_, y = _unique(y, return_inverse=True) @@ -127,6 +129,7 @@ def transform(self, y): Returns ------- y : array-like of shape (n_samples,) + Labels as normalized encodings. """ check_is_fitted(self) y = column_or_1d(y, warn=True) @@ -147,6 +150,7 @@ def inverse_transform(self, y): Returns ------- y : ndarray of shape (n_samples,) + Original encoding. """ check_is_fitted(self) y = column_or_1d(y, warn=True) From 48471369743c120809865ce528eb409cb9a92ad6 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Tue, 6 Jul 2021 12:33:43 +0200 Subject: [PATCH 2/2] remove trailing spaces --- sklearn/preprocessing/_label.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sklearn/preprocessing/_label.py b/sklearn/preprocessing/_label.py index f1547e03aeeb6..d460dd3c3f9ab 100644 --- a/sklearn/preprocessing/_label.py +++ b/sklearn/preprocessing/_label.py @@ -112,7 +112,7 @@ def fit_transform(self, y): Returns ------- y : array-like of shape (n_samples,) - Encoded labels. + Encoded labels. """ y = column_or_1d(y, warn=True) self.classes_, y = _unique(y, return_inverse=True) @@ -129,7 +129,7 @@ def transform(self, y): Returns ------- y : array-like of shape (n_samples,) - Labels as normalized encodings. + Labels as normalized encodings. """ check_is_fitted(self) y = column_or_1d(y, warn=True) @@ -150,7 +150,7 @@ def inverse_transform(self, y): Returns ------- y : ndarray of shape (n_samples,) - Original encoding. + Original encoding. """ check_is_fitted(self) y = column_or_1d(y, warn=True)