【发布时间】:2020-12-10 08:04:56
【问题描述】:
有没有办法自动获取 LSTM 中 input_shape 参数的形状,然后将该形状设置为 input_shape 参数。 我希望能够让循环神经网络根据数据的形状自动设置输入形状。 谢谢。
dataset_train = pd.read_csv(dataset_path)
training_set = dataset_train.iloc[:, :].values
from sklearn.preprocessing import MinMaxScaler
sc = MinMaxScaler(feature_range=(0, 1))
training_set_scaled = sc.fit_transform(x)
print(len(training_set_scaled))
print(len(dataset_train))
X_train = []
y_train = []
for i in range(past_days, len(training_set_scaled) - future_days + 1):
X_train.append(training_set_scaled[i - past_days:i, 0])
y_train.append(training_set_scaled[i + future_days - 1:i + future_days, 0])
X_train, y_train = np.array(X_train), np.array(y_train)
## Building and Training the RNN
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import LSTM
from tensorflow.keras.layers import Dropout
### Initialising the RNN
regressor = Sequential()
### Adding the first LSTM layer and some Dropout regularisation
regressor.add(LSTM(units=50, input_shape= (?) , return_sequences=True))
regressor.add(Dropout(0.2))
### Adding a second LSTM layer and some Dropout regularisation
regressor.add(LSTM(units=50, return_sequences=True))
regressor.add(Dropout(0.2))
### Adding a third LSTM layer and some Dropout regularisation
regressor.add(LSTM(units=50, return_sequences=True))
regressor.add(Dropout(0.2))
### Adding a fourth LSTM layer and some Dropout regularisation
regressor.add(LSTM(units=50))
regressor.add(Dropout(0.2))
### Adding the output layer
regressor.add(Dense(units=1))
### Compiling the RNN
regressor.compile(optimizer='adam', loss='mean_squared_error')
【问题讨论】:
标签: python machine-learning keras deep-learning recurrent-neural-network