Sklearn 的 MinMaxScaler 只返回零 [英] Sklearn's MinMaxScaler only returns zeros

查看:78
本文介绍了Sklearn 的 MinMaxScaler 只返回零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 sklearn 中的 preprocessing 将某个数字缩放到 0 - 1 的范围.这就是我所做的:

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

但是 data_scaled 只包含零.我究竟做错了什么?

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

推荐答案

当我尝试使用 sklearn.preprocessing 中的 MinMaxScaler 进行缩放时,我遇到了同样的问题.当我使用形状为 numpy 数组作为列表时,Scaler 返回零,即 [1, n] 如下所示:

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]]

我将数组的形状更改为 [n, 1].在您的情况下,它需要以下内容

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]]

然后 MinMaxScaler 以正确的方式工作.

Then MinMaxScaler worked in proper way.

这篇关于Sklearn 的 MinMaxScaler 只返回零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆