属性错误:'Series'对象没有属性 'reshape' [英] AttributeError: 'Series' object has no attribute 'reshape'

查看:107
本文介绍了属性错误:'Series'对象没有属性 'reshape'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 sci-kit 学习线性回归算法.在缩放 Y 目标特征时:

I'm using sci-kit learn linear regression algorithm. While scaling Y target feature with:

Ys = scaler.fit_transform(Y)

我得到了

ValueError: 需要二维数组,得到一维数组:

ValueError: Expected 2D array, got 1D array instead:

在那之后,我使用:

Ys = scaler.fit_transform(Y.reshape(-1,1))

但是又报错了:

AttributeError: 'Series' 对象没有属性 'reshape'

AttributeError: 'Series' object has no attribute 'reshape'

所以我检查了 pandas.Series 文档页面,它说:

So I checked pandas.Series documentation page and it says:

reshape(*args, **kwargs) 自 0.19.0 版起已弃用.

reshape(*args, **kwargs) Deprecated since version 0.19.0.

推荐答案

Solution waslinked on reformed method on 文档页面.

Solution was linked on reshaped method on documentation page.

Insted Y.reshape(-1,1) 你需要使用:

Insted of Y.reshape(-1,1) you need to use:

Y.values.reshape(-1,1)

这篇关于属性错误:'Series'对象没有属性 'reshape'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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