Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sklearn's MinMaxScaler only returns zeros

I am trying to scale a some number to a range of 0 - 1 using preprocessing from sklearn. Thats what i did:

data = [44.645, 44.055, 44.54, 44.04, 43.975, 43.49, 42.04, 42.6, 42.46, 41.405]
min_max_scaler = preprocessing.MinMaxScaler(feature_range=(0, 1))
data_scaled = min_max_scaler.fit_transform([data])
print data_scaled

But data_scaled only contains zeros. What am i doing wrong?

like image 478
Gizmo Avatar asked Sep 17 '14 08:09

Gizmo


People also ask

What does MinMaxScaler return?

MinMaxScaler can return values smaller than 0 and greater than 1. MinMaxScaler is one of the most commonly used scaling techniques in Machine Learning (right after StandardScaler). From sklearns documentation: Transform features by scaling each feature to a given range.

What is the range of MinMaxScaler?

MinMaxScaler scales all the data features in the range [0, 1] or else in the range [-1, 1] if there are negative values in the dataset. This scaling compresses all the inliers in the narrow range [0, 0.005].

How does a min/max scaler work?

MinMax Scaler shrinks the data within the given range, usually of 0 to 1. It transforms data by scaling features to a given range. It scales the values to a specific value range without changing the shape of the original distribution.


Video Answer


1 Answers

I had the same problem when I tried scaling with MinMaxScaler from sklearn.preprocessing. Scaler returned me zeros when I used a shape a numpy array as list, i.e. [1, n] which looks like the following:

data = [[44.645, 44.055, 44.54, 44.04, 43.975, 43.49, 42.04, 42.6, 42.46, 41.405]]

I changed the shape of array to [n, 1]. In your case it would like the following

data = [[44.645], 
        [44.055], 
        [44.540], 
        [44.040], 
        [43.975], 
        [43.490], 
        [42.040], 
        [42.600], 
        [42.460], 
        [41.405]]

Then MinMaxScaler worked in proper way.

like image 100
Antonina Avatar answered Sep 29 '22 10:09

Antonina