Python numpy - DepricationWarning:不推荐使用1d数组作为数据

时间:2018-04-19 17:56:45

标签: python arrays numpy scikit-learn deep-learning

我对数据科学/ python很新,目前我正在研究一些深度学习算法,我想在输入和输出数据中使用一个变量。我有4个输入和1个输出。我使用以下结构:

AWS Mobile Hub

并获得以下警告,当我使用StandardScale时,数组:

 samples = np.zeros(nb_samples, dtype=[('input', float, 4), ('output', float, 1)] )

我认为问题在于我的结构如下:

 DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise 
 ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your
  data has a single feature or X.reshape(1, -1) if it contains a single sample.

看起来应该是这样的:

 [ [x0,x1,x2,x3], y0 ]

我发现了一些类似的问题,但没有一个答案适合我。

如何解决此警告?什么是确切的问题?

1 个答案:

答案 0 :(得分:3)

我正在使用0.19.1,当我尝试扩展此数组时,我确实遇到了错误。但这是适合我的转变:

samples = np.zeros(nb_samples, dtype=[('input', float, 4), ('output', float, 1)])
x = samples['input']     # shape=(nb_samples, 4)
y = samples['output']    # shape=(nb_samples,)

scaler = StandardScaler()
scaler.fit_transform(x, y)  # does the same with and without `y`

inputoutput的分离特别适用于StandardScaler,因为它仅缩放x而不对y做任何事情。 In factyPipeline兼容性的“直通参数”。如果您忽略此警告并直接转换samples,则output也会被修改,而这不是您想要的。