機械学習の練習のためpythonでLSTMによる予測を行いました。
モデルをfitさせる事はできたのですがpredictでモデルにテストデータを入れた時以下のようなエラーが出ました。
元のデータは仮想通貨の価格と適当なデータの二次元配列です。
その二つの値から仮想通貨の価格を予想しようとしています。
機械学習初心者のため調べても理由がわかりませんでした。
よろしければお知恵をお貸しください。
python
1out_neurons = 1 2in_neurons=2 3hidden_neurons = 300 4length_of_sequences = 20 5 6model = Sequential() 7model.add(LSTM(hidden_neurons, batch_input_shape=(None, length_of_sequences, in_neurons), return_sequences=False)) 8model.add(Dense(out_neurons)) 9model.add(Activation("linear")) 10model.compile(loss="mean_squared_error", optimizer="adam",) 11 12from keras.callbacks import EarlyStopping 13 14early_stopping = EarlyStopping(monitor='val_loss', mode='auto', patience=0) 15history = model.fit(X_train, y_train, batch_size=600, epochs=10, validation_split=0.1, callbacks=[early_stopping]) 16#この部分でエラー 17pred_data = model.predict(X_test)
エラー文です。
python
1 2ValueError Traceback (most recent call last) 3<ipython-input-35-5ac4a9b3e137> in <module>() 4----> 1 pred_data = model.predict(X_test) 5 2 plt.plot(y_test, label='train') 6 3 plt.plot(pred_data, label='pred') 7 4 plt.legend(loc='upper left') 8 5 plt.show() 9 10/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/engine/training.py in predict(self, x, batch_size, verbose, steps) 11 1150 'argument.') 12 1151 # Validate user data. 13-> 1152 x, _, _ = self._standardize_user_data(x) 14 1153 if self.stateful: 15 1154 if x[0].shape[0] > batch_size and x[0].shape[0] % batch_size != 0: 16 17/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_array_lengths, batch_size) 18 752 feed_input_shapes, 19 753 check_batch_axis=False, # Don't enforce the batch size. 20--> 754 exception_prefix='input') 21 755 22 756 if y is not None: 23 24/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/engine/training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix) 25 124 ': expected ' + names[i] + ' to have ' + 26 125 str(len(shape)) + ' dimensions, but got array ' 27--> 126 'with shape ' + str(data_shape)) 28 127 if not check_batch_axis: 29 128 data_shape = data_shape[1:] 30 31ValueError: Error when checking input: expected lstm_4_input to have 3 dimensions, but got array with shape (0, 1)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。