Skip to content
BoKSA

MNIST EDA Assignment

MNIST: From Data to Your First Neural Network

In this individual assignment you work through a small but complete machine-learning workflow using the MNIST dataset of handwritten digits:

understand the data → EDA → train/test split → preprocessing → baseline → neural network → evaluation

You work in a Jupyter notebook. Each step tells you which pandas or Keras function you need, explains what it does, and gives you a code skeleton or a hint. You write the relevant line of code yourself. Most of the plotting code (matplotlib and seaborn) is already written for you, so you can focus on what each step does and why it is needed.

Download the notebook Open the MNIST Explorer


Learning objectives

After this assignment you can:

  • inspect a pandas DataFrame with commonly used functions;
  • count labels, select and group data, and create simple new variables;
  • interpret relevant EDA results;
  • explain why train, validation and test data serve different purposes;
  • justify preprocessing choices for MNIST;
  • determine a simple baseline;
  • build, compile and train a simple Dense neural network with Keras yourself;
  • interpret learning curves, test accuracy and a confusion matrix;
  • explain why good performance on MNIST is limited evidence for a real-world application.

Step 1: Set up your environment

You need Python, a virtual environment and VS Code with the Jupyter extension. If you haven't set these up yet, follow the Python Setup Manual first.

In short, once uv and VS Code are installed:

1
2
3
4
5
6
7
8
mkdir mnist-assignment
cd mnist-assignment
uv python pin 3.12
uv venv
# activate (Windows):  .venv\Scripts\activate
# activate (macOS):    source .venv/bin/activate
uv pip install ipykernel pandas matplotlib seaborn scikit-learn keras tensorflow
code .

Put the downloaded MNIST_EDA_Assignment_Responsible_AI.ipynb in the mnist-assignment folder, open it in VS Code and select the .venv kernel (see section 8 of the setup manual).

TensorFlow and Python versions

TensorFlow doesn't always support the newest Python release straight away. If uv pip install tensorflow fails, rebuild your environment with an older Python version (for example uv python pin 3.12 and uv venv). See section 5.4 of the setup manual.


Step 2: Explore first with the MNIST Explorer

The MNIST Explorer is an interactive website that shows the EDA and data preparation for MNIST, together with the pandas code that goes with each step. You can change settings, such as the test size, stratification, the "bright pixel" threshold or where you fit a scaler, and see straight away what happens.

The first half of the notebook follows the Explorer's four stages. Each matching section in the notebook links to its chapter in the Explorer, so you can switch between the two as you work.

Explorer stage Explorer chapter Notebook section
Understand Provenance 2. Load MNIST
One image, one row 2.1 First pandas steps, 3.1 Take a sample
Sanity check 3. Sanity check
Protect evaluation Train / val / test split 4. Create train and test data, 10.1 Validation set
Explore train Class distribution 5.1 How are the digits distributed?
Look at images 5.2 Look at real images
Pixels → features 6. From pixels to simple EDA features
The average digit 6.3 The average digit per class
Data quality 7. Check data quality
Prepare Choose preprocessing 8. Choose preprocessing
Conclusion & production fit 9. EDA conclusion, 20. Final conclusion

The Explorer stops at data preparation. From section 10 onwards (baseline, neural network, evaluation) you work in the notebook only.

The Explorer is not the assignment

The Explorer helps you understand and predict results. Don't copy its code without thinking. Write the code in the notebook yourself, and check whether your output matches what the Explorer shows.


Step 3: Work through the notebook

The notebook has 20 sections in two parts.

Part A: Exploratory data analysis (sections 1–9)

  1. Setup: load the libraries.
  2. Load MNIST: 70,000 images of 28 × 28 = 784 pixels, one image per row.
  3. Sanity check: labels, missing values and pixel range.
  4. Train/test split: a stratified 80/20 split, made before you do any EDA.
  5. EDA on the training data: the class distribution and real images.
  6. From pixels to features: mean_intensity, active_pixels, bright_pixels, grouping, and the average digit per class.
  7. Data quality: missing values, range and duplicates.
  8. Preprocessing: decide which steps are needed and normalise to 0–1.
  9. EDA conclusion: three sentences that summarise your findings.

Part B: Your first neural network (sections 10–20)

  1. Validation set: split validation off the training data, never off the test data.
  2. Baseline: random and majority baselines.
  3. Build a Keras Sequential model: 784 → Dense(512, ReLU) → Dense(10, Softmax).
  4. Compile with Adam and sparse categorical cross-entropy.
  5. Train for 10 epochs with validation data.
  6. Learning curves: look for signs of overfitting.
  7. Test set: evaluate only once, at the end.
  8. Predictions: Softmax scores and argmax.
  9. Confusion matrix: which digits get confused?
  10. Real errors: look at misclassified images.
  11. Final conclusion.

Throughout the notebook you'll find short questions and interpretation cells marked with >. Answer them in your own words. They are just as important as the code.


Deliverable

Hand in your completed notebook (.ipynb) with all cells executed, so the outputs and plots are visible. Make sure that:

  • every ... placeholder has been replaced with working code;
  • all short questions and interpretation cells have been answered;
  • the EDA conclusion (section 9) and the final conclusion (section 20) are written in your own words;
  • the notebook runs from top to bottom without errors (Restart the kernel, then Run All).

Why this matters for Responsible AI

A neural network that scores around 98% on MNIST can look impressive. But MNIST consists of clean, centred, grey-scale digits written by a limited group of people. In your final conclusion, think critically about how far this result carries over to a real application. The Explorer's Conclusion & production fit chapter asks: would future inputs look like this? Being honest about what your evaluation does and does not show is one of the core skills of responsible AI development.