scikit learn 中的预处理 - 单个样本 - 折旧警告 [英] Preprocessing in scikit learn - single sample - Depreciation warning
问题描述
在 Ubuntu 下全新安装 Anaconda 时...我在使用 Scikit-Learn 进行分类任务之前以各种方式预处理我的数据.
On a fresh installation of Anaconda under Ubuntu... I am preprocessing my data in various ways prior to a classification task using Scikit-Learn.
from sklearn import preprocessing
scaler = preprocessing.MinMaxScaler().fit(train)
train = scaler.transform(train)
test = scaler.transform(test)
这一切都很好,但如果我有一个新样本(下面的温度),我想分类(因此我想以相同的方式进行预处理,然后我得到
This all works fine but if I have a new sample (temp below) that I want to classify (and thus I want to preprocess in the same way then I get
temp = [1,2,3,4,5,5,6,....................,7]
temp = scaler.transform(temp)
然后我收到弃用警告...
Then I get a deprecation warning...
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.
所以问题是我应该如何重新调整这样的单个样本?
So the question is how should I be rescaling a single sample like this?
我想另一种选择(不是很好)是...
I suppose an alternative (not very good one) would be...
temp = [temp, temp]
temp = scaler.transform(temp)
temp = temp[0]
但我相信有更好的方法.
But I'm sure there are better ways.
推荐答案
听听警告是什么意思:
如果您的数据具有单个特征/列,则重塑您的数据 X.reshape(-1, 1)和 X.reshape(1, -1) 如果它包含单个样本.
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.
对于您的示例类型(如果您有多个特征/列):
For your example type(if you have more than one feature/column):
temp = temp.reshape(1,-1)
对于一个特征/列:
temp = temp.reshape(-1,1)
这篇关于scikit learn 中的预处理 - 单个样本 - 折旧警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!