如何在多 class 化模型中获得每个 class 的百分比预测
How to get percentage prediction for every class in multi-classification model
我已经训练了 10 classes 的顺序模型。
classes = ['Begin', 'Choose', 'Connection', 'Navigation',
'Next', 'Previous', 'Start', 'Stop', 'Hello', 'Web']
模型输出:
out = loaded_model.predict(image_sequence)
print(out)
[[5.3001270e-02 1.8615163e-05 3.5275782e-05 1.8662749e-02 3.3778408e-01
3.2624280e-01 2.6934301e-02 2.2875501e-03 2.3302139e-01 2.0118954e-03]]
我想得到每个 class 的预测百分比,如下所示:
Begin: 80%
Choose: 10%
Connection: 6%
and so on.....
classes = ['Begin', 'Choose', 'Connection', 'Navigation',
'Next', 'Previous', 'Start', 'Stop', 'Hello', 'Web']
out = [5.3001270e-02, 1.8615163e-05, 3.5275782e-05,
1.8662749e-02, 3.3778408e-01, 3.2624280e-01,
2.6934301e-02, 2.2875501e-03, 2.3302139e-01,
2.0118954e-03]
percentage_list = []
for i in range(len(out)):
percentage_list.append("{0:.2%}".format(out[i]))
my_result = list(zip(classes, percentage_list))
for i in range(len(my_result)):
print(my_result[i])
结果:
('Begin', '5.30%')
('Choose', '0.00%')
('Connection', '0.00%')
('Navigation', '1.87%')
('Next', '33.78%')
('Previous', '32.62%')
('Start', '2.69%')
('Stop', '0.23%')
('Hello', '23.30%')
('Web', '0.20%')
我已经训练了 10 classes 的顺序模型。
classes = ['Begin', 'Choose', 'Connection', 'Navigation',
'Next', 'Previous', 'Start', 'Stop', 'Hello', 'Web']
模型输出:
out = loaded_model.predict(image_sequence)
print(out)
[[5.3001270e-02 1.8615163e-05 3.5275782e-05 1.8662749e-02 3.3778408e-01
3.2624280e-01 2.6934301e-02 2.2875501e-03 2.3302139e-01 2.0118954e-03]]
我想得到每个 class 的预测百分比,如下所示:
Begin: 80%
Choose: 10%
Connection: 6%
and so on.....
classes = ['Begin', 'Choose', 'Connection', 'Navigation',
'Next', 'Previous', 'Start', 'Stop', 'Hello', 'Web']
out = [5.3001270e-02, 1.8615163e-05, 3.5275782e-05,
1.8662749e-02, 3.3778408e-01, 3.2624280e-01,
2.6934301e-02, 2.2875501e-03, 2.3302139e-01,
2.0118954e-03]
percentage_list = []
for i in range(len(out)):
percentage_list.append("{0:.2%}".format(out[i]))
my_result = list(zip(classes, percentage_list))
for i in range(len(my_result)):
print(my_result[i])
结果:
('Begin', '5.30%')
('Choose', '0.00%')
('Connection', '0.00%')
('Navigation', '1.87%')
('Next', '33.78%')
('Previous', '32.62%')
('Start', '2.69%')
('Stop', '0.23%')
('Hello', '23.30%')
('Web', '0.20%')