This file contains 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
def weighted_categorical_crossentropy(weights): | |
weights = K.variable(weights) | |
def loss(y_true, y_pred): | |
# scale predictions so that the class probas of each sample sum to 1 | |
y_pred /= K.sum(y_pred, axis=-1, keepdims=True) | |
# clip to prevent NaN's and Inf's | |
y_pred = K.clip(y_pred, K.epsilon(), 1 - K.epsilon()) | |
# calc |
This file contains 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
#model | |
model = Sequential() | |
#input | |
model.add(LSTM(units=50, return_sequences=True, activation='tanh', batch_size=batch_size, stateful=True, input_shape = (x_train_final.shape[1], x_train_final.shape[2]))) | |
model.add(Dropout(0.2)) | |
#hidden layer 1 | |
model.add(LSTM(units=60, return_sequences=True, activation='tanh', stateful=True)) | |
model.add(Dropout(0.2)) | |
#hidden layer 2 | |
model.add(LSTM(units=60, return_sequences=True, activation='tanh', stateful=True)) |