MinMaxScaler() of sklearn.preprocessing

This is just a note demonstrating how to scale and de-scale data using MinMaxScaler() of sklearn.preprocessing.

In [4]: import sklearn.preprocessing

In [5]: X=sklearn.preprocessing.MinMaxScaler()

In [7]: X.fit_transform([1.,2.,3.,4.])
Out[7]: array([ 0.        ,  0.33333333,  0.66666667,  1.        ])

In [10]: X.scale_
Out[10]: 0.33333333333333331

In [14]: X.min_
Out[14]: -0.33333333333333331

In [17]: 4.*X.scale_+X.min_  # from non-scaled value to scaled value, a.k.a., transform
Out[17]: 1.0

In [19]: (1-X.min_)/X.scale_ # from scaled value back to scaled_value, a.k.a., inverse_transform
Out[19]: 4.0



References:

[1] http://stackoverflow.com/questions/24724717/scikit-learn-minmaxscaler-produces-slightly-different-results-than-a-numpy-imple

No comments: