The row ID that scored 100%: data leakage in the Bot-IoT dataset
I rebuilt an old IoT botnet-detection project and, before training anything, tested each column on its own. One of them, the dataset's row ID, separated attacks from normal traffic perfectly. Here's how that happens, why many reported scores on this dataset deserve suspicion, and what an honest evaluation looks like.
The dataset
Bot-IoT was recorded in a UNSW Canberra cyber range: simulated IoT devices, normal traffic and botnet attacks. I used the authors' 5% extract with their "10-best features" and official train/test split: 2,934,817 training rows and 733,705 test rows.
The first thing the data tells you is how lopsided it is:
| Class | Training rows | Share |
|---|---|---|
| DDoS | 1,541,315 | 52.52% |
| DoS | 1,320,148 | 44.98% |
| Reconnaissance | 72,919 | 2.48% |
| Normal | 370 | 0.013% |
| Theft | 65 | 0.002% |
Trap one: accuracy
The test set contains 107 normal flows out of 733,705. A "model" that answers attack for everything scores 99.985% accuracy while recognising none of them. Any result on this dataset quoted as accuracy alone tells you almost nothing, so I compared models on balanced accuracy, macro F1, and two numbers a security team actually cares about: the false-positive rate (normal traffic flagged as an attack) and the attack detection rate.
Trap two: leakage
Before training a real model, I ran a simple screen: train a tiny decision tree on one column at a time and measure balanced accuracy, where 0.5 is a coin flip. A column that predicts the label almost perfectly on its own is either the most informative feature in the world or something that shouldn't be a feature at all.
for col in columns:
x = encode(sample[col]).reshape(-1, 1)
tree = DecisionTreeClassifier(max_depth=3, class_weight="balanced")
tree.fit(x_train, y_train)
score = balanced_accuracy_score(y_test, tree.predict(x_test))
| Column | Score alone | What it is |
|---|---|---|
pkSeqID | 1.000 | Row ID |
N_IN_Conn_P_DstIP | 0.990 | Inbound connections per destination IP |
dport | 0.973 | Destination port |
N_IN_Conn_P_SrcIP | 0.965 | Inbound connections per source IP |
daddr | 0.962 | Destination IP address |
seq | 0.913 | Argus record sequence number |
srate | 0.907 | Source packets per second |
A row number carries no information about network behaviour. It scores perfectly because of how the dataset was assembled: normal and attack records were captured and numbered in separate blocks, so the ID encodes the label. IP addresses and ports behave similarly. They identify the lab's victim machines and attack setup, which a model memorises and which won't exist on any other network.
Measuring the inflation
To put numbers on it, I retrained the best model (Random Forest) four ways and evaluated each on the same untouched test set:
| Experiment | Balanced acc. | Macro F1 | False positives | Relied on most |
|---|---|---|---|---|
| A. Behavioural features only | 0.979 | 0.957 | 1.87% | srate |
| B. + identifier columns | 1.000 | 0.992 | 0.00% | pkSeqID |
| C. Row ID only | 1.000 | 0.999 | 0.00% | pkSeqID |
| D. No whole-capture counts | 0.862 | 0.764 | 21.50% | srate |
Experiment C is the finding: a model that knows nothing about network traffic beats every honest model. When a paper reports near-perfect results on Bot-IoT without saying which columns were removed, it may be measuring the dataset's numbering, not attack detection.
Experiment D is the uncomfortable follow-up. The two connection-count features are counted over the entire capture. They're real behavioural signals (floods produce huge connection counts), but a detector running live wouldn't have whole-capture totals up front. Without them, the false-positive rate jumps from 1.87% to 21.5%. A deployable version would need those counts computed over a sliding time window.
The honest results
With identifiers removed, training-only rebalancing (cap the huge classes, oversample the rare ones; the test set is never touched) and five models on 14 behavioural features:
| Model | Balanced acc. | Macro F1 | False positives | Train time |
|---|---|---|---|---|
| Random Forest | 0.979 | 0.957 | 1.87% | 3 s |
| KNN | 0.974 | 0.917 | 2.80% | <1 s |
| AdaBoost | 0.936 | 0.880 | 1.87% | 56 s |
| MLP | 0.945 | 0.770 | 3.74% | 14 s |
| LSTM | 0.932 | 0.523 | 2.80% | 46 s |
Two details are worth pointing out. Random Forest's plain accuracy (99.62%) is lower than the always-attack baseline, yet it's by far the better detector. And the LSTM's recall looks fine class by class, but it labels about 0.23% of attacks as normal. That's roughly 1,670 attacks hiding in a "normal" bucket that genuinely holds only 107 flows, which is why its macro F1 is 0.52. The deep sequence model was slower and worse than a Random Forest on tabular flow features.
A checklist I'll reuse
- Report per-class metrics, never accuracy alone, whenever classes are imbalanced.
- Run a single-feature screen before modelling. Anything near-perfect on its own needs an explanation.
- Ask whether each feature exists at detection time. Whole-dataset aggregates often don't.
- Rebalance training data only; evaluate on the real class mix.
- Be honest about sample size. My 1.87% false-positive rate is 2 of 107 flows; one more error moves it by about a point.
More writing
- Five ways JWT validation fails, and how to test for them
- Hiding instructions in a document: indirect prompt injection in a RAG chatbot
- Access control belongs in the retrieval layer, not the prompt
- Quarantining a compromised EC2 instance in seconds with GuardDuty and Lambda
- Working the OWASP Top 10 by hand: PortSwigger and TryHackMe
- TryHackMe Vulnversity: enumeration to root