【发布时间】:2018-11-26 19:35:41
【问题描述】:
我尝试了几个小时来解决这个问题,但当我尝试反转缩放数据时却无法解决。
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.
我的数据列都是整数或浮点数(没有分类)。另外,我删除了日期列。
我做错了什么?
【问题讨论】:
-
抱歉,我的意思是我的数据由整数(整数,如 1 或 0)和带小数的数字(如 23.567)组成。
-
请编辑您的问题以修复您的帖子。这比发表评论更有帮助,因为不是每个人都会通过 cmets 阅读
-
Alamoot,我不确定你的意思。我应该在主题中修正什么以使其更清晰?
-
我在谈论您的评论:
Sorry, I mean my data consists of integers (whole binary numbers like 1 or 0) and numbers with decimals (like 23.567)点击问题底部的edit按钮并修复问题。 -
很遗憾,我的帖子没有编辑选项。不知道为什么。
标签: python python-3.x machine-learning scikit-learn