Your First Neural Network (Keras / MNIST)

Deep Learning Keras MNIST hands-on

The "hello world" of deep learning

MNIST is 70,000 tiny 28×28 images of handwritten digits 0–9. Training a network to classify them is the classic first project — and Keras makes it just a handful of lines.

This page walks the five steps every deep-learning project follows: load data, build the model, compile it, fit (train), and predict. Master this loop and bigger projects are just variations.

The five steps, animated

From raw digit images to a trained classifier predicting a "7" — watch the workflow run.

The code, step by step

1. Load & prep normalize

mnist.load_data(); divide pixels by 255 so inputs are 0–1 (scaling).

2. Build Sequential

FlattenDense(128, relu)Dense(10, softmax). A simple stack of layers.

3. Compile loss + optimizer

Pick categorical cross-entropy and the Adam optimizer.

4. Fit model.fit()

Train for a few epochs on mini-batches. Watch accuracy climb.

5. Evaluate & predict ~98%

Score on the test set, then predict new digits. A basic net hits ~98%.

Things to try next

Experiments

Add a hidden layer, add dropout, switch the optimizer, change the learning rate, or read the training curves to spot overfitting. Then graduate to a CNN for higher accuracy on images.