How to calculate F1 Macro in Keras?

since Keras 2.0 metrics f1, precision, and recall have been removed. The solution is to use a custom metric function: from keras import backend as K def f1(y_true, y_pred): def recall(y_true, y_pred): “””Recall metric. Only computes a batch-wise average of recall. Computes the recall, a metric for multi-label classification of how many relevant items are … Read more

Custom loss function in Keras based on the input data

I have come across 2 solutions to the question you asked. You can pass your input (scalar only) as an argument to the custom loss wrapper function. def custom_loss(i): def loss(y_true, y_pred): return K.mean(K.square(y_pred – y_true), axis=-1) + something with i… return loss def baseline_model(): # create model i = Input(shape=(5,)) x = Dense(5, kernel_initializer=”glorot_uniform”, … Read more

When does keras reset an LSTM state?

Cheking with some tests, I got to the following conclusion, which is according to the documentation and to Nassim’s answer: First, there isn’t a single state in a layer, but one state per sample in the batch. There are batch_size parallel states in such a layer. Stateful=False In a stateful=False case, all the states are … Read more

tech