I've looked for a similar situation but I'm getting this problem after implementing what I thought should be the fix. I'm making a LSTM model to predict a solar system's power output using a data set from kaggle. The function is
def power_prediction_model():
df = pd.read_csv('powerData/power_plant_generation_data_limited.csv')
df = df.rename(columns={'DATE_TIME': 'Date'})
df = df[['Date', 'AC_POWER']]
df['Date'] = pd.to_datetime(df['Date'])
data = df.filter(['AC_POWER'])
dataset = data.values
training_data_len = math.ceil(len(dataset) * .8)
# Scale the data
scaler = MinMaxScaler(feature_range=(0, 1))
scaled_data = scaler.fit_transform(dataset)
# Create the training data set
train_data = scaled_data[0:training_data_len, :]
# Split the data into x_train and y_train data sets
x_train = [] # independent training variables
y_train = [] # dependant or target variable
for i in range(1500, len(train_data)):
x_train.append(train_data[i - 1500:i, 0])
y_train.append(train_data[i, 0])
# convert to numpy arrays
x_train = np.array(x_train)
y_train = np.array(y_train)
# reshape the data to 3D
x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))
# build the LSTM model
model = Sequential()
model.add(LSTM(50, return_sequences=True, input_shape=(x_train[1], 1)))
model.add(LSTM(50, return_sequences=False))
model.add(Dense(25))
model.add(Dense(1))
with the error coming from the line model.add(LSTM(50, return_sequences=True, input_shape=(x_train[1], 1)))
The array being passed to the model is converted to a numpy array so I'm stuck on where the TypeError is coming from.
CodePudding user response:
x_train[1]
need to be x_train.shape[1]