在Ubuntu上全新安装Anaconda后,我正在使用Scikit-Learn在进行分类任务之前以多种方式对我的数据进行预处理。
from sklearn import preprocessing
scaler = preprocessing.MinMaxScaler().fit(train)
train = scaler.transform(train)
test = scaler.transform(test)
这一切都很好,但如果我有一个新的样本(temp below),我想要对其进行分类(因此我想以同样的方式进行预处理),那么我会得到
temp = [1,2,3,4,5,5,6,....................,7]
temp = scaler.transform(temp)
然后我收到一个弃用警告...
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.
那么问题是我应该如何重新缩放像这样的单个样本呢?
我想,另一种选择(不是很好的选择)可能是……
temp = [temp, temp]
temp = scaler.transform(temp)
temp = temp[0]
但我相信有更好的方法。
X.reshape(-1, 1)
,如果你的数据只有一个样本,就使用X.reshape(1, -1)
。如果你的数据不是numpy数组,则首先使用np.array(data)
。 - pzelasko