ARMA_GBR/SVR ValueError: Expected 2D array, got 1D array instead: array=[2856.3394 2850.637 2844.9326 2837.7214]. 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
Hi, i have a problem concerning executing the code
number [12]
features = 4 # this number is derived from the paper "The stock price based on the ARIMA_SVM combination model _ cheng changpin.(Chinese)". Since the prediction is the best when using 4 days close price to predict
forward =30
window = 150 # the rolling window should be as large as possible. Better larger than 100, since the time series ARMA model can't get inverted matrics if the time series is too short
length = 1
index_predict, index_real = [], []
for i in range(forward):
test_window = test_C[i:i+window]
coeff = WT(test_window, lv=4, n=4)
results = AR_MA(coeff)
Y_ = NonlinReg(coeff, regressor='GBR', length=length, features = features)[-1:]
D_series = []
for j in range(len(results)):
D_series.append(results[j].predict(window, window+length-1, dynamic=True))
index_predict.append(Y_)
index_real.append(test_C[i+window:i+window+length].values)
it give me this error
ValueError Traceback (most recent call last)
<ipython-input-13-b2d1bf8912bc> in <module>
8 coeff = WT(test_window, lv=4, n=4)
9 results = AR_MA(coeff)
---> 10 Y_ = NonlinReg(coeff, regressor='GBR', length=length, features = features)[-1:]
11 D_series = []
12 for j in range(len(results)):
~/PycharmProjects/PHBS_TQFML-StockIndex-Wavelet-Transformation-ARIMA-ML-Model/Project/model.py in NonlinReg(coeff, regressor, features, interval, length)
136 for i in range(length):
137 X_ = np.concatenate((X_, np.array([np.concatenate((X_[-1][-features+1:], Y_[[-interval-1]]))])))
--> 138 Y_ = np.concatenate((Y_, gbr.predict(X_[-1])))
139
140 if regressor == 'SVR':
/usr/local/lib/python3.6/dist-packages/sklearn/ensemble/_gb.py in predict(self, X)
2565 The predicted values.
2566 """
-> 2567 X = check_array(X, dtype=DTYPE, order="C", accept_sparse='csr')
2568 # In regression we can directly return the raw value from the trees.
2569 return self._raw_predict(X).ravel()
/usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
554 "Reshape your data either using array.reshape(-1, 1) if "
555 "your data has a single feature or array.reshape(1, -1) "
--> 556 "if it contains a single sample.".format(array))
557
558 # in the future np.flexible dtypes will be handled like object dtypes
ValueError: Expected 2D array, got 1D array instead:
array=[2856.3394 2850.637 2844.9326 2837.7214].
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.
Hi, i have a problem concerning executing the code
it give me this error