10000 DOC added to preprocessing docstring examples (#11752) · scikit-learn/scikit-learn@76d763b · GitHub
[go: up one dir, main page]

Skip to content

Commit 76d763b

Browse files
adrinjalalirth
authored andcommitted
DOC added to preprocessing docstring examples (#11752)
1 parent 0efaf2d commit 76d763b

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

sklearn/preprocessing/data.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,20 @@ class MaxAbsScaler(BaseEstimator, TransformerMixin):
831831
The number of samples processed by the estimator. Will be reset on
832832
new calls to fit, but increments across ``partial_fit`` calls.
833833
834+
Examples
835+
--------
836+
>>> from sklearn.preprocessing import MaxAbsScaler
837+
>>> X = [[ 1., -1., 2.],
838+
... [ 2., 0., 0.],
839+
... [ 0., 1., -1.]]
840+
>>> transformer = MaxAbsScaler().fit(X)
841+
>>> transformer
842+
MaxAbsScaler(copy=True)
843+
>>> transformer.transform(X)
844+
array([[ 0.5, -1. , 1. ],
845+
[ 1. , 0. , 0. ],
846+
[ 0. , 1. , -0.5]])
847+
834848
See also
835849
--------
836850
maxabs_scale: Equivalent function without the estimator API.
@@ -1068,6 +1082,21 @@ class RobustScaler(BaseEstimator, TransformerMixin):
10681082
.. versionadded:: 0.17
10691083
*scale_* attribute.
10701084
1085+
Examples
1086+
--------
1087+
>>> from sklearn.preprocessing import RobustScaler
1088+
>>> X = [[ 1., -2., 2.],
1089+
... [ -2., 1., 3.],
1090+
... [ 4., 1., -2.]]
1091+
>>> transformer = RobustScaler().fit(X)
1092+
>>> transformer
1093+
RobustScaler(copy=True, quantile_range=(25.0, 75.0), with_centering=True,
1094+
with_scaling=True)
1095+
>>> transformer.transform(X)
1096+
array([[ 0. , -2. , 0. ],
1097+
[-1. , 0. , 0.4],
1098+
[ 1. , 0. , -1.6]])
1099+
10711100
See also
10721101
--------
10731102
robust_scale: Equivalent function without the estimator API.
@@ -1580,6 +1609,20 @@ class Normalizer(BaseEstimator, TransformerMixin):
15801609
copy (if the input is already a numpy array or a scipy.sparse
15811610
CSR matrix).
15821611
1612+
Examples
1613+
--------
1614+
>>> from sklearn.preprocessing import Normalizer
1615+
>>> X = [[4, 1, 2, 2],
1616+
... [1, 3, 9, 3],
1617+
... [5, 7, 5, 1]]
1618+
>>> transformer = Normalizer().fit(X) # fit does nothing.
1619+
>>> transformer
1620+
Normalizer(copy=True, norm='l2')
1621+
>>> transformer.transform(X)
1622+
array([[0.8, 0.2, 0.4, 0.4],
1623+
[0.1, 0.3, 0.9, 0.3],
1624+
[0.5, 0.7, 0.5, 0.1]])
1625+
15831626
Notes
15841627
-----
15851628
This estimator is stateless (besides constructor parameters), the
@@ -1707,6 +1750,20 @@ class Binarizer(BaseEstimator, TransformerMixin):
17071750
set to False to perform inplace binarization and avoid a copy (if
17081751
the input is already a numpy array or a scipy.sparse CSR matrix).
17091752
1753+
Examples
1754+
--------
1755+
>>> from sklearn.preprocessing import Binarizer
1756+
>>> X = [[ 1., -1., 2.],
1757+
... [ 2., 0., 0.],
1758+
... [ 0., 1., -1.]]
1759+
>>> transformer = Binarizer().fit(X) # fit does nothing.
1760+
>>> transformer
1761+
Binarizer(copy=True, threshold=0.0)
1762+
>>> transformer.transform(X)
1763+
array([[1., 0., 1.],
1764+
[1., 0., 0.],
1765+
[0., 1., 0.]])
1766+
17101767
Notes
17111768
-----
17121769
If the input is a sparse matrix, only the non-zero values are subject
@@ -1771,7 +1828,28 @@ class KernelCenterer(BaseEstimator, TransformerMixin):
17711828
sklearn.preprocessing.StandardScaler(with_std=False).
17721829
17731830
Read more in the :ref:`User Guide <kernel_centering>`.
1831+
1832+
Examples
1833+
--------
1834+
>>> from sklearn.preprocessing import KernelCenterer
1835+
>>> from sklearn.metrics.pairwise import pairwise_kernels
1836+
>>> X = [[ 1., -2., 2.],
1837+
... [ -2., 1., 3.],
1838+
... [ 4., 1., -2.]]
1839+
>>> K = pairwise_kernels(X, metric='linear')
1840+
>>> K
1841+
array([[ 9., 2., -2.],
1842+
[ 2., 14., -13.],
1843+
[ -2., -13., 21.]])
1844+
>>> transformer = KernelCenterer().fit(K)
1845+
>>> transformer
1846+
KernelCenterer()
1847+
>>> transformer.transform(K)
1848+
array([[ 5., 0., -5.],
1849+
[ 0., 14., -14.],
1850+
[ -5., -14., 19.]])
17741851
"""
1852+
17751853
def __init__(self):
17761854
# Needed for backported inspect.signature compatibility with PyPy
17771855
pass

0 commit comments

Comments
 (0)
0