我想为我的二进制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分数,准确性和召回率?(如果不复杂,也可以使用交叉验证分数,但此答案不是必需的)
感谢您的任何帮助!