在 Ubuntu 下全新安装 Anaconda...在使用 Scikit-Learn 进行分类任务之前,我正在以各种方式预处理我的数据。
from sklearn import preprocessing
scaler = preprocessing.MinMaxScaler().fit(train)
train = scaler.transform(train)
test = scaler.transform(test)
这一切都很好,但如果我有一个新样本(低于温度)我想分类(因此我想以同样的方式进行预处理,那么我得到
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]
但我相信还有更好的方法。
最佳答案
只要听听警告告诉你什么:
Reshape your data either X.reshape(-1, 1) if your data has a single feature/column and X.reshape(1, -1) if it contains a single sample.
对于您的示例类型(如果您有多个功能/列):
temp = temp.reshape(1,-1)
对于一个特征/列:
temp = temp.reshape(-1,1)
关于python - scikit learn中的预处理-单个样本-折旧警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35082140/