我想计算我的二进制 KerasClassifier 模型的精度、召回率和 F1 分数,但没有找到任何解决方案。
这是我的实际代码:
# Split dataset in train and test data
X_train, X_test, Y_train, Y_test = train_test_split(normalized_X, Y, test_size=0.3, random_state=seed)
# Build the model
model = Sequential()
model.add(Dense(23, input_dim=45, kernel_initializer='normal', activation='relu'))
model.add(Dense(1, kernel_initializer='normal', activation='sigmoid'))
# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
tensorboard = TensorBoard(log_dir="logs/{}".format(time.time()))
time_callback = TimeHistory()
# Fit the model
history = model.fit(X_train, Y_train, validation_split=0.3, epochs=200, batch_size=5, verbose=1, callbacks=[tensorboard, time_callback])
然后我预测新的测试数据,得到这样的混淆矩阵:
y_pred = model.predict(X_test)
y_pred =(y_pred>0.5)
list(y_pred)
cm = confusion_matrix(Y_test, y_pred)
print(cm)
但是有没有任何解决方案来获得准确度分数、F1 分数、精度和召回率?(如果不复杂,还有交叉验证分数,但对于这个答案不是必需的)
感谢您的任何帮助!