python - scikit learn中的预处理-单个样本-折旧警告

标签 python scikit-learn deprecation-warning

在 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/

相关文章:

python - 均方误差返回不合理的高数字

Python/matplotlib : getting rid of matplotlib. mpl 警告

python - 如何更改与logging.captureWarnings()关联的记录器?

python - 在 numpy 中,用空元组和省略号索引数组有什么作用?

python - 如何最好地使用 InstallShield 在 Windows 上安装 Python + 模块

python - 升级 Django 版本 : Best Practice

python - 在 Python 中合并两个对象

python - 堆叠直方图不会堆叠

scikit-learn - Scikit-learn MultinomialNB 中出现内存不足错误

android - 偏好 Activity : getFragmentManager() has been deprecated