# why i get the F1score greater than 1 for CNN+SVM in python

I want to create an CNN+SVM in python to classify my data which consist of 3 classes. the problem I get the F1score greater than 1. this is my code. every help will apricate so much.

```
def recall_m(y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
recall = true_positives / (possible_positives + K.epsilon())
return recall
def precision_m(y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
precision = true_positives / (predicted_positives + K.epsilon())
return precision
def f1_m(y_true, y_pred):
precision = precision_m(y_true, y_pred)
recall = recall_m(y_true, y_pred)
return 2*((precision*recall)/(precision+recall+K.epsilon()))
from keras import regularizers
from tensorflow.keras.layers import BatchNormalization
from tensorflow.keras.regularizers import l2
reset_seeds()
model = Sequential()
init=keras.initializers.HeNormal()
bias=keras.initializers.Constant(0.018)
model.add(Conv1D(filters=128, kernel_size=15, padding='same', kernel_initializer=init,
input_shape=(1062, 1), strides = 1))
model.add(Activation('relu'))
model.add(MaxPooling1D(pool_size=3,data_format='channels_last'))
model.add(Dropout(0.2))
model.add(BatchNormalization())
model.add(Conv1D(filters=128, kernel_size=15, padding='same', kernel_initializer=init,
strides=1))
model.add(Activation('relu'))
model.add(Conv1D(filters=128, kernel_size=15, padding='same', kernel_initializer=init,
strides=1))
model.add(Activation('relu'))
model.add(MaxPooling1D(pool_size=3,data_format='channels_last'))
model.add(Dropout(0.2))
model.add(BatchNormalization())
model.add(Flatten())
model.add(Dense(12,bias_initializer=bias))
model.add(Activation('relu'))
model.add(Dropout(0.3))
model.add(Dense(3, kernel_regularizer=regularizers.l1_l2(l1=1e-6, l2=1e-6)))
model.add(Activation('softmax'))
opt = adam_v2.Adam(learning_rate=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=1e-
6, amsgrad=False)
loss_fn = tf.keras.losses.SquaredHinge(reduction="auto", name="squared_hinge")
reset_seeds()
model.compile(loss=loss_fn, optimizer=opt, metrics=['acc',f1_m,precision_m, recall_m])
```

the shape of my trainingset is (17,1062,1)

How many English words

do you know?

do you know?

Test your English vocabulary size, and measure

how many words do you know

Online Test
how many words do you know

Powered by Examplum