Last active
February 14, 2020 00:45
-
-
Save csaguiar/1f4b37c2827a0cfd4dd0db8c59541371 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sequence_size = X_train.shape[1] | |
| n_features = 1 | |
| n_subsequences = 4 | |
| subsequence_size = int(sequence_size / n_subsequences) | |
| # Reshaping to be (samples, subsequences, sequence, feature) | |
| X_train = X_train.reshape(-1, n_subsequences, subsequence_size, n_features) | |
| X_val = X_val.reshape(-1, n_subsequences, subsequence_size, n_features) | |
| cnn_lstm_model = Sequential([ | |
| TimeDistributed( | |
| Conv1D( | |
| filters=8, | |
| kernel_size=4, | |
| strides=1, | |
| padding="same", | |
| activation="relu" | |
| ), | |
| input_shape=(n_subsequences, subsequence_size, n_features) | |
| ), | |
| TimeDistributed(Flatten()), | |
| LSTM( | |
| units=1, | |
| input_shape=(sequence_size, n_features) | |
| ), | |
| Dense( | |
| 1, | |
| activation="sigmoid", | |
| name="output", | |
| ) | |
| ]) | |
| optimizer = Adam(lr=0.001) | |
| # Compiling the model | |
| cnn_lstm_model.compile( | |
| optimizer=optimizer, | |
| loss="binary_crossentropy", | |
| metrics=["accuracy"] | |
| ) | |
| cnn_lstm_model.summary() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment