前提・実現したいこと
pythonでNNのLSTMを動かしていますが、エラーの意味も直し方も全くわかりません。
初心者がやる問題ではないと思うのですが直し方を教えてくれる方がいると助かります。
よろしくお願いいたします。
エラーメッセージは以下になります。
発生している問題・エラーメッセージ
ValueError: Input 0 is incompatible with layer sequential: expected shape=(None, None, 1), found shape=[None, 100, 2]
### 該当のソースコード python import keras import pandas as pd import numpy as np import math import random import csv import matplotlib.pyplot as plt def df(): read = pd.read_csv('test_2.csv', delimiter = ',',encoding='utf-8_sig',names=('signal1','signal2')) return read #読み込み read = df() def _load_data(data, n_prev = 100): docX, docY = [], [] for i in range(len(data)-n_prev): docX.append(data.iloc[i:i+n_prev].values) docY.append(data.iloc[i+n_prev].values) alsX = np.array(docX) alsY = np.array(docY) return alsX, alsY def train_test_split(read, test_size=0.1, n_prev = 100): #This just splits data to training and testing parts ntrn = round(len(read) * (1 - test_size)) ntrn = int(ntrn) X_train, y_train = _load_data(read.iloc[0:ntrn], n_prev) X_test, y_test = _load_data(read.iloc[ntrn:], n_prev) return (X_train, y_train), (X_test, y_test) length_of_sequences = 100 (X_train, y_train), (X_test, y_test) = train_test_split(read, n_prev =length_of_sequences) from keras.models import Sequential from keras.layers.core import Dense, Activation from keras.layers.recurrent import LSTM in_out_neurons = 1 hidden_neurons = 300 model = Sequential() model.add(LSTM(hidden_neurons, batch_input_shape=(None, length_of_sequences, in_out_neurons), return_sequences=False)) model.add(Dense(in_out_neurons)) model.add(Activation("linear")) model.compile(loss="mean_squared_error", optimizer="rmsprop") #model.fit(X_train, y_train, batch_size=600, epochs=20, validation_split=0.2) from keras.callbacks import EarlyStopping early_stopping = EarlyStopping(monitor='val_loss', patience=2) model.fit(X_train, y_train, batch_size=600, epochs=20, validation_split=0.5, callbacks=[early_stopping]) predicted = model.predict(X_test) dataf = pd.DataFrame(predicted[:200]) dataf.columns = ["predict"] dataf["input"] = y_test[:200] dataf.plot(figsize=(15, 5)) plt.show()
あなたの回答
tips
プレビュー