Reputation: 65
This is the example from official: http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html
>>> from sklearn.preprocessing import MinMaxScaler
>>>
>>> data = [[-1, 2], [-0.5, 6], [0, 10], [1, 18]]
>>> scaler = MinMaxScaler()
>>> print(scaler.fit(data))
MinMaxScaler(copy=True, feature_range=(0, 1))
>>> print(scaler.data_max_)
[ 1. 18.]
>>> print(scaler.transform(data))
[[ 0. 0. ]
[ 0.25 0.25]
[ 0.5 0.5 ]
[ 1. 1. ]]
>>> print(scaler.transform([[2, 2]]))
[[ 1.5 0. ]]
The official document is as below.
transform(X)[source] Scaling features of X according to feature_range.
Parameters: X : array-like, shape [n_samples, n_features]
Input data that will be transformed.
Why am I seeing [[ 1.5 0. ]]
as an output when the default value for feature_range
parameter is (0, 1)
?
Upvotes: 3
Views: 1405
Reputation: 3583
Consider the transform operation like this:
import numpy as np
data = np.array(data)
f1 = data[:,0]
mn = f1.min()
mx = f1.max()
(f1- mn)/ (mx - mn)
note: the transform operation is constructed from your initial data. once the tranform operation is constructed, it will operate on your secondary data and does not re-scale it again. you may have problem with parameter feature_range. In that case you should know that after minmaxtransform it rescale the data.
Upvotes: 2