8000 [MRG+1] Added examples to docstrings of MinMaxScaler and StandardScal… · musically-ut/scikit-learn@93c17f1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 93c17f1

Browse files
loduralityjmschrei
authored andcommitted
[MRG+1] Added examples to docstrings of MinMaxScaler and StandardScaler (scikit-learn#9380)
[MRG+2] Added examples to docstrings of MinMaxScaler and StandardScaler
1 parent 71408e0 commit 93c17f1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

sklearn/preprocessing/data.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,24 @@ class MinMaxScaler(BaseEstimator, TransformerMixin):
244244
.. versionadded:: 0.17
245245
*data_range_*
246246
247+
Examples
248+
--------
249+
>>> from sklearn.preprocessing import MinMaxScaler
250+
>>>
251+
>>> data = [[-1, 2], [-0.5, 6], [0, 10], [1, 18]]
252+
>>> scaler = MinMaxScaler()
253+
>>> print(scaler.fit(data))
254+
MinMaxScaler(copy=True, feature_range=(0, 1))
255+
>>> print(scaler.data_max_)
256+
[ 1. 18.]
257+
>>> print(scaler.transform(data))
258+
[[ 0. 0. ]
259+
[ 0.25 0.25]
260+
[ 0.5 0.5 ]
261+
[ 1. 1. ]]
262+
>>> print(scaler.transform([[2, 2]]))
263+
[[ 1.5 0. ]]
264+
247265
See also
248266
--------
249267
minmax_scale: Equivalent function without the estimator API.
@@ -504,6 +522,24 @@ class StandardScaler(BaseEstimator, TransformerMixin):
504522
The number of samples processed by the estimator. Will be reset on
505523
new calls to fit, but increments across ``partial_fit`` calls.
506524
525+
Examples
526+
--------
527+
>>> from sklearn.preprocessing import StandardScaler
528+
>>>
529+
>>> data = [[0, 0], [0, 0], [1, 1], [1, 1]]
530+
>>> scaler = StandardScaler()
531+
>>> print(scaler.fit(data))
532+
StandardScaler(copy=True, with_mean=True, with_std=True)
533+
>>> print(scaler.mean_)
534+
[ 0.5 0.5]
535+
>>> print(scaler.transform(data))
536+
[[-1. -1.]
537+
[-1. -1.]
538+
[ 1. 1.]
539+
[ 1. 1.]]
540+
>>> print(scaler.transform([[2, 2]]))
541+
[[ 3. 3.]]
542+
507543
See also
508544
--------
509545
scale: Equivalent function without the estimator API.

0 commit comments

Comments
 (0)
0