gpt4 book ai didi

python - 预期为二维数组,但在尝试反转缩放数据时却得到一维数组

转载 作者:行者123 更新时间:2023-11-30 08:58:15 35 4
gpt4 key购买 nike

我尝试解决这个问题几个小时,但当我尝试反转缩放数据时却无法做到这一点。

 In: print(yhat.shape), print(test_X[:, 0:].shape)
Out:(1155, 1), (1155, 1, 37)

# invert scaling for forecast

inv_yhat=np.dstack((yhat, test_X[:, 0:])).shape
inv_yhat = scaler.inverse_transform(inv_yhat)
inv_yhat = inv_yhat[:,0]


---------------------------------------------------------------------------
ValueError: Traceback (most recent call last)
<ipython-input-334-779bdcd26d3e> in <module>()
3
4 inv_yhat=np.dstack((yhat, test_X[:, 0:])).shape
----> 5 inv_yhat = scaler.inverse_transform(inv_yhat)
6 inv_yhat = inv_yhat[:,0]

/anaconda3/lib/python3.6/site-packages/sklearn/preprocessing/data.py in inverse_transform(self, X)
381 check_is_fitted(self, 'scale_')
382
--> 383 X = check_array(X, copy=self.copy, dtype=FLOAT_DTYPES)
384
385 X -= self.min_

/anaconda3/lib/python3.6/site-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
439 "Reshape your data either using array.reshape(-1, 1) if "
440 "your data has a single feature or array.reshape(1, -1) "
--> 441 "if it contains a single sample.".format(array))
442 array = np.atleast_2d(array)
443 # To ensure that array flags are maintained

ValueError: Expected 2D array, got 1D array instead:
array=[1.155e+03 1.000e+00 3.800e+01].
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.

我的数据列都是整数或 float (无分类)。另外,我删除了日期列。

我做错了什么?

最佳答案

答案就在你面前。您使用一维数组作为输入,但 scikit-learn 中的数据始终必须是二维的:

Reshape your data either using array.reshape(-1, 1) if your data has a single feature.

尝试如下:

inv_yhat = scaler.inverse_transform(inv_yhat.reshape(-1,1))

关于python - 预期为二维数组,但在尝试反转缩放数据时却得到一维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50901281/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com