Sklearn's MinMaxScaler only returns zeros

sklearn install
sklearn github
sklearn linear regression
sklearn tutorial
sklearn install mac
jupyter sklearn
uninstall sklearn
matplotlib sklearn

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?

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.

Scikit-learn Tutorial: Machine Learning in Python – Dataquest, library contains a lot of efficient tools for machine learning and statistical modeling including classification, regression, clustering and dimensionality reduction. sklearn 0.0 pip install sklearn Copy PIP instructions. Latest version. Released: Jul 15, 2015 A set of python modules for machine learning and data mining.

This is because data is a int32 or int64 and the MinMaxScaler needs a float. Try this:

import numpy as np
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([np.float32(data)])
print data_scaled

Scikit-Learn In Python, and check the output. You will have detailed error information there. Do you have nosetests installed? scikit-learn. scikit-learn is a Python module for machine learning built on top of SciPy and is distributed under the 3-Clause BSD license. The project was started in 2007 by David Cournapeau as a Google Summer of Code project, and since then many volunteers have contributed.

You're putting your data into a list for some reason, but you shouldn't:

data_scaled = min_max_scaler.fit_transform(data)

Difference between scikit-learn and sklearn, that provides many unsupervised and supervised learning algorithms. It's built upon some of the technology you might already be familiar with, like NumPy, pandas, and Matplotlib! Scikit-learn (formerly scikits.learn and also known as sklearn) is a free software machine learning library for the Python programming language. It features various classification, regression and clustering algorithms including support vector machines, random forests, gradient boosting, k-means and DBSCAN, and is designed to interoperate with the Python numerical and scientific libraries NumPy

data = []
data = np.array(data)
data.append([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.reshape(10,-1))
data = data_scaled.reshape( -1, 10)
print data

The reason behind this is when you're trying to apply fit_transform method of StandardScaler object to array of size (1, n) you obviously get all zeros, because for each number of array you subtract from it mean of this number, which equal to number and divide to std of this number. If you want to get correct scaling of your array, you should convert it to array with size (n, 1).

See the correct answer of this link :

What is Scikit-Learn?, Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems March 2015. scikit-learn 0.16.0 is available for download . July 2014. scikit-learn 0.15.0 is available for download . July 14-20th, 2014: international sprint. During this week-long sprint, we gathered 18 of the core contributors in Paris.

scikit-learn, Python Machine Learning: Machine Learning and Deep Learning with Python, Scikit-learn, and TensorFlow 2, 3rd Edition scikit-learn. scikit-learn is a Python module for machine learning built on top of SciPy and is distributed under the 3-Clause BSD license. The project was started in 2007 by David Cournapeau as a Google Summer of Code project, and since then many volunteers have contributed.

scikit-learn/scikit-learn, Introduction to Machine Learning with Python: A Guide for Data Scientists Learn how to build an end-to-end machine learning pipeline for a sales forecasting problem. Explore various preprocessing and data cleaning techniques.

scikit-learn · PyPI, Scikit-learn is a free software machine learning library for the Python programming language. It features various classification, regression and clustering  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more ImportError: cannnot import name 'Imputer' from 'sklearn.preprocessing'

Comments
  • How did you fix your problem? The answers below, did not work for me.
  • This does not solve the questions asked. Printing data_scaled still returns the zeros
  • But if i don't do that this error will occur: TypeError: 'numpy.float64' object does not support item assignment
  • What do sklearn.__version__ and numpy.version.version say on your system? Because the above code works for me with recent versions.
  • I'm using the same sklearn, NumPy 1.8.1, and Python 2.7.8 and also Python 3.4.1. When I run the code in your question I get an array of zeros; when I use the line in my answer I get a non-zero array as expected, with the first value being 1 and the last being 0. You should test on another system.