Sklearn 转换错误:预期的二维数组,而是得到一维数组 [英] Sklearn transform error: Expected 2D array, got 1D array instead

查看:56
本文介绍了Sklearn 转换错误:预期的二维数组,而是得到一维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 sklearn 通过此代码转换数据.

I use sklearn to transform data with this code.

sc = MinMaxScaler()

test= df['outcome']
y = sc.fit_transform(test) 

它显示这样的错误.

ValueError: Expected 2D array, got 1D array instead:
array=[ 21000. 36000.  5000. ...  7000.  12000.  11000.].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

如何解决?

推荐答案

如果我没记错的话,MinMaxScalar 可以接受 pandas 数据帧 但不能接受 series,所以只需执行 test = df[['outcome']](一列数据框)而不是 test = df['outcome'](一系列).

If I remember correctly, MinMaxScalar can accept a pandas dataframe but not a series, so just do test = df[['outcome']] (dataframe with one column) instead of test = df['outcome'] (a series).

这篇关于Sklearn 转换错误:预期的二维数组,而是得到一维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆