繁体   English   中英

精确度、召回率、精确度和 f-measure 的分数小数

[英]Fraction decimal for accuracy, recall, precision and f-measure

我正在进行 CNN 实验,并使用准确率、召回率、精确率和 f-measure 指标评估构建的分类器。

结果值只有两个十进制小数位(即 0.95)。 我怎么能有至少 4 个小数位(即 0.9532)

此外,如何将结果值四舍五入以获得四舍五入数字的下限或上限?

from keras.models import Sequential
from keras.layers import Conv2D,Activation,MaxPooling2D,Dense,Flatten,Dropout
import numpy as np
from keras.preprocessing.image import ImageDataGenerator
from IPython.display import display
import matplotlib.pyplot as plt
from PIL import Image
from sklearn.metrics import classification_report, confusion_matrix
import keras
from keras.layers import BatchNormalization
from keras.optimizers import Adam
import pickle
from keras.models import load_model
classifier = load_model('32_With_Dropout_rl_001_1_layer_2.h5')
classifier1 = load_model('32_With_Dropout_rl_001_2_layers_2.h5')
classifier2 = load_model('32_With_Dropout_rl_001_3_layers_2.h5')
test_datagen = ImageDataGenerator(rescale = 1./255)
batchsize=10
test_set = test_datagen.flow_from_directory('/home/osboxes/Downloads/Downloads/Journal_Paper/Benign_Malicious/Spectrogram/Test/',
                                           target_size = (200,200),
                                           batch_size = batchsize,
                       shuffle=False,
                                           class_mode ='categorical')
Y_pred = classifier.predict_generator(test_set, steps= 1023 // batchsize+1)
y_pred = np.argmax(Y_pred, axis=1)
print('Confusion Matrix 1 layer')
print(confusion_matrix(test_set.classes, y_pred))
print('Classification Report')
target_names = test_set.classes
class_labels = list(test_set.class_indices.keys()) 
target_names = ['Bening', 'Malicious'] 
report = classification_report(test_set.classes, y_pred, target_names=class_labels)
print(report) 

Y_pred = classifier1.predict_generator(test_set, steps= 1023 // batchsize+1)
y_pred = np.argmax(Y_pred, axis=1)
print('Confusion Matrix 2 layers')
print(confusion_matrix(test_set.classes, y_pred))
print('Classification Report')
target_names = test_set.classes
class_labels = list(test_set.class_indices.keys()) 
target_names = ['Bening', 'Malicious'] 
report = classification_report(test_set.classes, y_pred, target_names=class_labels)
print(report) 

Y_pred = classifier2.predict_generator(test_set, steps= 1023 // batchsize+1)
y_pred = np.argmax(Y_pred, axis=1)
print('Confusion Matrix 3 layers')
print(confusion_matrix(test_set.classes, y_pred))
print('Classification Report')
target_names = test_set.classes
class_labels = list(test_set.class_indices.keys()) 
target_names = ['Bening', 'Malicious'] 
report = classification_report(test_set.classes, y_pred, target_names=class_labels)
print(report) 


#f = open('32_With_Dropout_rl_001_1_layer', 'rb')
#history = pickle.load(f)

#f = open('32_With_Dropout_rl_001_2_layers', 'rb')
#history1 = pickle.load(f)


#f = open('32_With_Dropout_rl_001_3_layers', 'rb')
#history2 = pickle.load(f)





您只需要在计算分类报告时使用output_dict参数。 如果设置为True ,则输出将作为字典(而不是字符串)返回。 然后您可以访问所有字段并根据需要修改它们(例如使用math.floormath.ceil )。

from math import ceil, floor

# do your stuff here
report = classification_report(..., output_dict=True)
# use the values of the report dictionary as you wish
print(floor(report[...]))

如果要将报告作为字符串获取,则应使用digits参数:

report = classification_report(..., digits=4)

此处查看文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM