Back to Projects
Deep Learning

Neural Network Design and Hyperparameter Search

A TensorFlow/Keras spam classifier built, tuned and evaluated over three exercises, with the finding that tuning did not beat the simple baseline.

Type
Deep Learning
Domain
Binary Classification
Methods
TensorFlow / Keras, Grid Search
Dataset
Public spam benchmark - 4,601 emails, 57 features

The Challenge

A simple two-layer network classified spam with 94.6% test accuracy, and a deeper, tuned network did not beat it.

The aim was to build intuition for how depth, epochs and batch size affect a neural network, and to test whether systematic tuning improves on a straightforward baseline.

Approach

01
Baseline
Standardised features, 80/20 train/test split (not stratified), and a 64-32 ReLU network with a sigmoid output.
02
Grid search
Manual loops over batch sizes 16, 32 and 64 and several epoch counts, repeated over many runs, with results logged to CSV.
03
Final model
Six hidden layers (64-32-16-16-16-16) with early stopping, batch size 16, evaluated over 10 runs on accuracy, precision, recall and F1.

Results

94.6%
Test accuracy of the 64-32 baseline (921 test emails)
94.5%
Average best accuracy across grid-search runs
92.0%
Tuned six-layer model, mean of 10 runs (F1 0.90)

The tuned model scored below the baseline, a useful result: added depth did not help on this tabular dataset, and the simpler network was the better choice.

Method note: grid-search configurations were selected on test accuracy, which makes the 94.5% optimistic; a separate validation split should drive selection. The split was not stratified.

How it was tested

TEST REPORTTEST REPORTSPAM CLASSIFIERSPAM CLASSIFIER
Checked
  • A tuned six-layer model compared with a simple baseline, over 10 runs, on accuracy, precision, recall and F1.
Did not work
  • The tuned six-layer model (92.0%) scored below the 64-32 baseline (94.6%): added depth did not help on this tabular data.
Limits
  • Grid-search configurations were selected on test accuracy, which makes the 94.5% optimistic; a separate validation split should drive selection.
  • The train/test split was not stratified.

Technology Stack

Python TensorFlow / Keras scikit-learn pandas NumPy
Interested in this work or something similar?