LSTM模型可预测股票的日收益。我曾经使用pd.qcut()
将数据四分位数以这些四分位数作为稀疏标签进行分组。
然后我建立了LSTM模型:
regressor = Sequential()
regressor.add(LSTM(units = 50, return_sequences = True,
input_shape = (X_train_scaled_sequence.shape[1], X_train_scaled_sequence.shape[2])))
regressor.add(Dropout(DROUPOUT))
regressor.add(LSTM(units = 50, return_sequences = True))
regressor.add(Dropout(DROUPOUT))
regressor.add(LSTM(units = 50, return_sequences = True))
regressor.add(Dropout(DROUPOUT))
regressor.add(LSTM(units = 50))
regressor.add(Dropout(DROUPOUT))
regressor.add(Dense(units = 10, activation='softmax'))
opt = SGD(lr=0.001)
regressor.compile(loss = tf.keras.losses.SparseCategoricalCrossentropy(),
optimizer = opt,
metrics = [tf.keras.metrics.Accuracy()])
history = regressor.fit(X_train_scaled_sequence, Y_train_scaled_sequence,
validation_data=(X_val_scaled_sequence, Y_val_scaled_sequence), epochs = EPOCHS, batch_size = BATCH_SIZE)
数据形状:
print(X_train_scaled_sequence.shape)
>>> (2575, 60, 154)
print(Y_train_scaled_sequence.shape)
>>> (2575,)
但是我得到了这个错误,
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (None, 10) and (None, 1) are incompatible