Мои данные состоят из 26 столбцов и 231000 строк.Я пытался исправить ошибку в течение нескольких дней, но я все еще не уверен, что нужно сделать.Пожалуйста, дайте свое понимание этой проблемы.Ниже приведен мой полный код
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn import datasets, linear_model
from matplotlib import pyplot as plt
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from keras.layers import RepeatVector
from keras.layers import TimeDistributed
# load dataset
dataframe = pd.read_csv("AHPS_26C_Norm.csv", header=None)
dataset = dataframe.values
X = dataset[1:, 1:26].astype(float)
Y = dataset[1:, 0]
X = np.array(X)
Y = np.array(Y)
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.20, random_state=42)
n_steps = len(X_train)
n_features = 25
batch_size = 1
X_train = X_train.reshape(1, n_steps, n_features)
Y_train = Y_train.reshape(1, n_steps)
# create model
model = Sequential()
model.add(LSTM(100, activation='relu', batch_input_shape=(1, n_steps, n_features)))
model.add(RepeatVector(n_steps))
model.add(LSTM(100, activation='softmax', return_sequences=True))
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
# fit model
model.fit(X_train, Y_train, epochs=300, validation_data = (X_test, Y_test), batch_size= batch_size, verbose=0)
print(model.summary())
# Final evaluation of the model
scores = model.evaluate(X_train, Y_train, verbose=0)
print("Accuracy: %.2f%%" % (scores[1] * 100))
Ниже приведена ошибка, которую я получил:
Traceback (most recent call last):
File "C:/Users/Iliya Juhari/.PyCharmCE2018.3/config/scratches/scratch_3.py", line 40, in <module>
model.fit(X_train, Y_train, epochs=300, validation_data = (X_test, Y_test), batch_size= batch_size, verbose=0)
File "C:\Users\Iliya Juhari\PycharmProjects\untitled\venv\lib\site-packages\keras\engine\training.py", line 1154, in fit
batch_size=batch_size)
File "C:\Users\Iliya Juhari\PycharmProjects\untitled\venv\lib\site-packages\keras\engine\training.py", line 621, in _standardize_user_data
exception_prefix='target')
File "C:\Users\Iliya Juhari\PycharmProjects\untitled\venv\lib\site-packages\keras\engine\training_utils.py", line 135, in standardize_input_data
'with shape ' + str(data_shape))
ValueError: Error when checking target: expected lstm_2 to have 3 dimensions, but got array with shape (1, 184800)