ENGINES ON

darkhex.dev00%
← All write-ups

ML security · 5 min read · Thesis notes

Why I don't trust a perfect detection score

During my thesis on ML-based DDoS detection, one model hit 100% on every metric. That was the moment I knew something was wrong.

The suspicious result

Accuracy, precision, recall, F1: all perfect. In security, that almost never means you built a perfect detector. It usually means the model has seen the answers.

# first run (training data)
accuracy   1.000
f1         1.000   <- too good to be true

Where the answers leaked in

Rule: split first. Everything else (scaling, SMOTE, feature selection) is fitted on the training fold only.

The fix

  1. Split the data before any preprocessing.
  2. Apply SMOTE inside each training fold only.
  3. Use 5-fold cross-validation and report the mean, not the best fold.
  4. Drop identifier-like features and check what the model actually relies on.

The honest numbers

After the fix, the best model scored an F1 of around 0.99, and the runner-up around 0.96 while training in a fraction of the time. Still strong, but now it's a number I can defend.

model A   f1 ≈ 0.99   train ≈ 525 s
model B   f1 ≈ 0.96   train ≈ 12 s
# exact per-class figures: see thesis appendix

What it means for a SOC

Pythonscikit-learnSMOTECross-validationDDoS