Я нахожусь на последней части моего кода и сталкиваюсь с операндами, которые не могут быть переданы вместе с фигурами (69331,4) (3,) (69331,4).
values = df.values
## full data without resampling
#values = df.values
# integer encode direction
# ensure all data is float
#values = values.astype('float32')
# normalize features
scaler = MinMaxScaler(feature_range=(0, 1))
scaled = scaler.fit_transform(values)
# frame as supervised learning
reframed = series_to_supervised(scaled, 1, 1)
# drop columns we don't want to predict
reframed.drop(reframed.columns[[0]], axis=1, inplace=True)
print(reframed.head())
Вот как я делю свои данные:
# split into train and test sets
values = reframed.values
n_train_time = 29713
train = values[:n_train_time, :]
test = values[n_train_time:, :]
##test = values[n_train_time:n_test_time, :]
# split into input and outputs
train_X, train_y = train[:, :-1], train[:, -1]
test_X, test_y = test[:, :-1], test[:, -1]
# reshape input to be 3D [samples, timesteps, features]
train_X = train_X.reshape((train_X.shape[0], 1, train_X.shape[1]))
test_X = test_X.reshape((test_X.shape[0], 1, test_X.shape[1]))
print(train_X.shape, train_y.shape, test_X.shape, test_y.shape)
# We reshaped the input into the 3D format as expected by LSTMs, namely [samples, timesteps, features].
Вот как я сделал свою модель:
model = Sequential()
model.add(LSTM(100, input_shape=(train_X.shape[1], train_X.shape[2])))
model.add(Dropout(0.2))
# model.add(LSTM(70))
# model.add(Dropout(0.3))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
Вот как я вписываюсь в мою сеть:
history = model.fit(train_X, train_y, epochs=20, batch_size=70, validation_data=(test_X, test_y), verbose=2, shuffle=False)
Вот как я делаю свои прогнозы:
# make a prediction
yhat = model.predict(test_X)
test_X = test_X.reshape((test_X.shape[0], 4))
# invert scaling for forecast
inv_yhat = np.concatenate((yhat, test_X[:,-3:]), axis=1)
Вот где происходит моя ошибка:
inv_yhat = scaler.inverse_transform(inv_yhat)
Ошибка:
ValueError: operands could not be broadcast together with shapes (69331,4) (3,) (69331,4)
Если я это сделаю:
print(train_X.shape, train_y.shape, test_X.shape, test_y.shape)
Я получу:
(29713, 1, 4) (29713,) (69331, 4) (69331, 1)
Любая помощь будет принята с благодарностью