为了账号安全,请及时绑定邮箱和手机立即绑定

预期的二维数组,得到一维数组

预期的二维数组,得到一维数组

白衣非少年 2021-12-17 14:35:11
我正在从 github 运行以下代码,但出现错误。怎么了?https://github.com/susanli2016/Machine-Learning-with-Python/blob/master/Time%20Series%20ANN%20%26%20LSTM%20VIX.ipynb细胞:# scale train and test data to [-1, 1]scaler = MinMaxScaler(feature_range=(-1, 1))train_sc = scaler.fit_transform(train)test_sc = scaler.transform(test)错误:ValueError: Expected 2D array, got 1D array instead:array=[17.24     18.190001 19.219999 ... 10.47     10.18     11.04    ].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.
查看完整描述

2 回答

?
月关宝盒

TA贡献1772条经验 获得超5个赞

制作那个笔记本的人使用的是一个非常旧版本的sklearn. 简而言之,您的特征具有形式[row_1, row_2...row_n],而它们本应具有形式[[row_1], [row_2]...[row_n]]。


因此,使用这个:


new_shape = (len(train), 1)


train_sc = scaler.fit_transform(np.reshape(train, new_shape))

test_sc = scaler.transform(np.reshape(test, new_shape))


查看完整回答
反对 回复 2021-12-17
?
泛舟湖上清波郎朗

TA贡献1818条经验 获得超3个赞

解决了添加以下方法的问题,这些方法显然将训练和测试对象转换为 numpy 数组。那是对的吗?


scaler = MinMaxScaler(feature_range=(-1, 1))

train_sc = scaler.fit_transform(train.values.reshape(-1, 1))

test_sc = scaler.transform(test.values.reshape(-1,1))


查看完整回答
反对 回复 2021-12-17
  • 2 回答
  • 0 关注
  • 196 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号