微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

scikit学习中的预处理-单个样本-折旧警告

如何解决scikit学习中的预处理-单个样本-折旧警告

只需听听警告告诉您的内容

如果数据具有单个要素/列,则重塑数据X.reshape(-1,1),如果包含单个样本,则重塑X.reshape(1,-1)。

对于您的示例类型(如果您有多个要素/列):

temp = temp.reshape(1,-1)

对于一个功能/列:

temp = temp.reshape(-1,1)

解决方法

在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,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]

但是我相信有更好的方法。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。