preprocessing.scale()给出零值

时间:2016-11-04 02:05:16

标签: python pandas numpy machine-learning scikit-learn

我正在尝试扩展其中一项功能" Energy"在一组特征f。在此之前,我将使用该功能的平均值替换NaN值。这是代码 -

import numpy as np
from sklearn import preprocessing

imputer = preprocessing.Imputer(missing_values="NaN", strategy="mean")
energy_array = f["Energy"].as_matrix()
energy_imputed = imputer.fit_transform([energy_array])
print(energy_imputed)

这给了我像 -

这样的值
[[-35.25608763 -36.1084797  -33.59742282 -33.50708972 -36.6088168
  -34.910584   -33.05457045 -36.18224291 -51.2727673  -34.12310309
  -30.73922078 -34.73504712 -29.52522131 -35.01537961 -37.0653397
  -31.3648709  -31.72301782 -20.83519558 -21.28122412 -19.61506732
  -16.30594604 -17.00392351 -36.53348958 -39.48780488 -48.17507062
  -40.48660468 -43.35718548 -39.27316566 -33.99082012 -39.26729086
  -33.35805303 -34.6512989  -34.99584325 -31.42133012 -34.93928771
  -37.92288655 -37.22567672 -42.91695745 -38.02082524 -29.1684119]]

现在,当我尝试扩展它时 -

energy_scaled = preprocessing.scale(energy_imputed)
print(energy_scaled)

我明白了 -

[[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
   0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
   0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
   0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
   0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
   0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
   0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
]]

为什么缩放后所有值都变为零?

0 个答案:

没有答案