Print sklearn probabilities cur, min and margins after prediction
Some checks failed
ArchLinux PKGBUILD / build (push) Has been cancelled
CentOs / centos8 (push) Has been cancelled
Docker Build / docker (push) Has been cancelled
FreeBSD Build / Build and Test (push) Has been cancelled
Build OpenWrt Packages / build (armsr-armv8) (push) Has been cancelled
Build OpenWrt Packages / build (malta-be) (push) Has been cancelled
Build OpenWrt Packages / build (ramips-mt7621) (push) Has been cancelled
Build OpenWrt Packages / build (x86-64) (push) Has been cancelled
RPM Build / build (push) Has been cancelled
Build / macOS-14 cc (push) Has been cancelled
Build / ubuntu-latest clang (push) Has been cancelled
Build / ubuntu-latest clang-1 (push) Has been cancelled
Build / ubuntu-22.04 clang-12 (push) Has been cancelled
Build / ubuntu-latest gcc (push) Has been cancelled
Build / ubuntu-latest gcc-1 (push) Has been cancelled
Build / ubuntu-latest gcc-2 (push) Has been cancelled
Build / ubuntu-22.04 gcc-10 (push) Has been cancelled
Build / ubuntu-22.04 gcc-9 (push) Has been cancelled
SonarQube Scan / Build and analyze (push) Has been cancelled

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
Toni Uhlig 2026-06-10 10:43:28 +02:00
parent 4acbe57d0a
commit 84285ae42d
No known key found for this signature in database
GPG key ID: 22C5333D922537D2

View file

@ -147,13 +147,20 @@ def predictClassFromProbabilities(probabilities, log_probabilities,
if probabilities[predicted_class] < min_probability:
predicted_class = 0
rejection_reason = 'min-probability'
rejection_reason = 'min-probability: {} < {}'.format(
round(probabilities[predicted_class], 3), round(min_probability, 3))
elif predicted_log_probability - none_log_probability < min_margin_to_none:
predicted_class = 0
rejection_reason = 'min-margin-to-none'
rejection_reason = 'min-margin-to-none: {} - {} = {} < {}'.format(
round(predicted_log_probability, 3), round(none_log_probability, 3),
round(predicted_log_probability - none_log_probability, 3),
round(min_margin_to_none, 3))
elif predicted_log_probability - second_best_log_probability < min_margin_to_second:
predicted_class = 0
rejection_reason = 'min-margin-to-second'
rejection_reason = 'min-margin-to-second: {} - {} = {} < {}'.format(
round(predicted_log_probability, 3), round(second_best_log_probability, 3),
round(predicted_log_probability - second_best_log_probability, 3),
round(min_margin_to_second, 3))
return predicted_class, rejection_reason
@ -258,12 +265,12 @@ def onJsonLineRecvd(json_dict, instance, current_flow, global_user_data):
probs += '{:>2.1f}, '.format(log_probabilities[i])
probs = probs[:-2]
print('DPI Engine detected: {}{:>24}{}, Predicted: {}{:>24}{}, Probabilities: {}'.format(
print('DPI Engine detected: {}{:>24}{}, Predicted: {}{:>24}{}, L-Probabilities: {}'.format(
color_start, json_dict['ndpi']['proto'].lower(), color_end,
color_start, y_text, color_end, probs))
if rejection_reason is not None:
print('{:>{}} {} rejected by {}'.format('[*]', MESSAGE_INDENT, y_text, rejection_reason))
print('{:>{}} rejected by {}'.format('[*]', MESSAGE_INDENT, rejection_reason))
if pred_failed is True:
pclass = isProtoClass(args.proto_class, json_dict['ndpi']['proto'].lower())