Deep-Learning Intrusion Detection
A deep neural network that flags attacks from network-traffic features, the kind you can collect by monitoring your own network. After an 11-day hyperparameter search I reported 90.78% accuracy at sorting attack records into their types on the UNSW-NB15 benchmark; this page also covers the models I tried and the mistakes I made.
The models in 3D
Every network I built that summer, each block one layer's output at its real shape. Pick a model from the menu and hover a layer for its size, or open the data view.

Final model
Convolution, two bidirectional LSTMs and a GRU, then three dense layers.
Hover over a block for its layer. Drag to turn, scroll to zoom.Tap a block for its layer. Drag to turn, pinch to zoom. Sizes compressed.
About this view: drawn from the 2023 notebooks
Shapes and parameter counts are computed from each model's layer code with Keras' formulas, checked against the one Keras summary that survives (206,158 parameters for the 18 July model). The view shows each network's structure, not its learned values. The data view was recomputed in 2026 with the notebook's own preprocessing: 300 training records per class, projected with a PCA fitted on normal traffic only.
The idea
This was my summer research through PACT, the Partnership for Proactive Cybersecurity Research and Training at the University of Arizona, sponsored by the Department of Energy and the National Nuclear Security Administration. I did the research myself, guided by the principal investigator of the Autonomic Computing Lab and my machine-learning mentor; the three of us authored the abstract and the poster I presented at the end of the summer.
At a glance
- Program
- PACT summer research, University of Arizona
- When
- Summer 2023
- Sponsors
- Department of Energy and National Nuclear Security Administration
- Research
- My own, guided by a principal investigator and a machine-learning mentor
- Output
- An abstract and a poster, authored by the three of us
A network intrusion detection system (NIDS) decides whether traffic is an attack. Most training data is normal, so models tend to raise too many false alarms or miss the rarer attacks. My idea was to read each record two ways: a convolution for patterns among related features, and recurrent layers (bidirectional LSTMs and a GRU) for order in them.
The data
UNSW-NB15 has 175,341 training and 82,332 test records, each a network flow described by 49 features and labeled normal or one of nine attack types. The classes are badly unbalanced: 56,000 normal records and 40,000 Generic attacks in the training set, but only 1,133 Shellcode and 130 Worms.
The numbers
| Training records | 175,341 |
|---|---|
| Test records | 82,332 |
| Features per record | 49 |
| Normal training records | 56,000 |
| Worms training records | 130 |
| Model inputs | 203196 scaled + 7 PCA |
I dropped the record ID and the binary attack label (the model predicts the attack type), one-hot encoded protocol, state and service, and min-max scaled everything to 0 to 1: 196 numbers per record. A PCA fitted only on normal training records, keeping 85% of their variance, adds 7 components that describe how far a record sits from normal, for the 203 inputs the poster lists.
Early on I ranked the features five ways (mutual information, chi² p-value and relevance, recursive feature elimination with five models, and importance scores) and averaged the ranks. The time-to-live features, sttl and dttl, came out on top, but the final model trained on all 203 inputs.
How I got to the final model
The git history and notebooks record the route. June went to the official training and test split, the feature study above, and small dense models on autoencoder and PCA features trained for up to 1,000 epochs (plots in the carousel below).
The numbers
| First CNN-BiLSTM that trained | 76.54%18 July · ten-class · test set |
|---|---|
| Keras Tuner trials | 185on Google Colab · 11 days |
| Search, 26 July | 90.78%my abstract |
| Search, 30 July | 90.96%my poster |
July was a string of experiments: a dense autoencoder that squeezed the inputs to 25 numbers, a first CNN-BiLSTM in outdated Keras syntax that never built, then cross-validation and a denoising autoencoder trained only on normal traffic, whose 12-number code became extra features. On 18 July the first CNN-BiLSTM that trained reached 76.54% ten-class accuracy on the test set, with the denoising autoencoder's codes as extra inputs. From 16 to 22 July I also chased MANomaly, two reconstructing autoencoders each judging the other's rebuilds, a GAN-style setup that never produced a classifier.
From 20 July to 1 August I added the GRU and ran a Keras Tuner search on Google Colab: 185 trials over 11 days. It reached 90.78% on 26 July, the figure in my abstract, and 90.96% on 30 July, the poster's. On 2 August I rebuilt the best trial locally and started a shorter local search.
The final model
The local rebuild, drawn in the viewer above, is the best trial plus the 7 PCA inputs and a second 80-unit dense layer: 253,470 parameters reading each record's 203 inputs as a sequence. A 32-filter convolution with a kernel 128 inputs wide feeds two bidirectional LSTMs (48 and 112 units each way), a 176-unit GRU and dense layers of 80, 80 and 10, one output per class with a sigmoid, with max pooling and batch normalization between the early layers. It trained with Adam and categorical cross-entropy, about 11 minutes per epoch on my Mac.
The tuning search
Hyperband searched the convolution's width and kernel, both pooling sizes, both LSTM widths, the GRU width, a dense layer, dropout, the learning rate and the batch size, up to 12 epochs a trial. Each dot is one trial; hover for its settings, or switch to the shorter search I ran on my laptop on 2 August.
What it scored
My abstract reported 90.78% multi-class accuracy and my poster 90.96%, the best validation scores of the Colab search. That search validated on the last fifth of the training file, which holds only attack records, so the numbers measure how well the model sorts attacks into their types. The poster also reported a 99.86% detection rate with an 18.67% false positive rate.
The charts below are the local run my notebook saved on 2 August; the poster showed the same confusion matrices and noted that they don't represent the tuned model.
Attacks are rarely missed: 98.81% were flagged. But so was 28% of normal traffic, the false-alarm problem the project set out to fix. Rare classes vanish: Analysis, Backdoor, DoS, Shellcode and Worms are never predicted, mostly called Exploits, while Generic (96%) and Reconnaissance (85%) separate well.
What I got wrong
Reading the notebooks again in 2026, I found plenty to point out to my 2023 self. The biggest family is leakage. In my local runs the search, early stopping and the epoch count all watched test accuracy, so every test number is optimistic; a validation split from the training data should have done that job. The min-max ranges came from training and test records combined, leaking a little of the test set into training. And my cross-validation kept training one network across folds, so later folds were scored on records it had already seen, inflating the 82.6% fold score.
The numbers
| Cross-validation fold score | 82.6%inflated |
|---|---|
| Accuracy stuck for 200 epochs | 68.06%the share of attacks |
| Second LSTM's sequence | 3 steps |
| Learning rate, best trial | 0.00067 |
| Learning rate, my rebuild | 0.0067ten times higher |
| Test accuracy, epoch to epoch | 57%–80% |
The Colab search had the opposite problem: its validation data held no normal traffic at all.
Keras' validation_split takes the last 20% of the training file without shuffling,
and in UNSW-NB15 that slice is all attacks, three quarters of them Generic. So the search ranked
models by how well they sorted attacks, never by how well they told attacks from normal traffic,
which is an intrusion detector's main job.
Several bugs hid in plain sight. My first encoder named its one-hot columns in the order services
appear in the file, but the columns come out sorted: the feature called
service: ftp that ranked eighth really held DHCP traffic. Early dense models and the
MANomaly discriminator ended in a softmax over a single unit, which always outputs 1; one model's
accuracy sat at exactly 68.06%, the share of attacks, for 200 epochs before I noticed. Later
models paired a sigmoid output with categorical cross-entropy instead of a softmax. The search's
batch-size setting only changed the input layer, so every trial trained at batch 32, and my local
search never left Hyperband's first round of 2-epoch trials before I stopped it after 11 hours.
The architecture also threw away what it was built to see. Max pooling by 32 cut the convolution's 203 positions to 6 steps and the first LSTM's 96 outputs to 3, so the second LSTM read a sequence three steps long. And the two dense layers of 80 have no activation, so together they act as one.
Then a slip of one decimal place: the best trial used a learning rate of 0.00067, and my local rebuild of it used 0.0067, ten times higher. Test accuracy then swung between 57% and 80% from one epoch to the next, and a rerun with identical settings ended 6 points lower. Finally, I kept my records apart. I ran cells out of order and overwrote outputs, and the tuner's checkpoints lived in my Google Drive, away from the notebooks, until I found them again in 2026. Only then could I match the reported numbers to the trials that produced them.
My 2023 plots
The figures I made along the way, as I saved them.








What I took from it
Look at what a number was scored on before trusting it. One glance at the validation slice's class mix would have shown no normal traffic, and a search answering a different question from the one an intrusion detector faces.
Know the trivial baseline. Twice a model scored exactly the share of attacks, and that was the tell that it had learned nothing; an always-guess-attack line on every chart would have caught both at once.
Keep the result, the settings and the code together, and load settings from the run instead of retyping them. That habit would have prevented the learning-rate slip and saved me tracing my own results years later.
Where it goes next
If I picked the model back up, I would retrain it the way those mistakes point: a shuffled validation split from the training data, scaling fitted on training records only, the test set touched once, and scores for attack-versus-normal as well as attack types. Then I would see whether the convolution-and-recurrence idea holds with pooling that leaves the LSTMs a real sequence.
The model already had a second life in my 2025 comparison with Snort. Real traffic would be the next one: my homelab ideas include feeding my own network into it, which needs a flow meter producing the dataset's features.
Want the details behind this one, or to talk about similar work?