Home › Learn AI › Neural Network Playground

Neural Network Playground

Build and train a real neural network in your browser. Pick a dataset, add hidden layers and neurons, choose ReLU, tanh or sigmoid, and watch the decision boundary, loss curve and weights change live.

Tap plot to add:
0Epoch
–Train loss
–Test loss
–Test accuracy
train loss   test loss

Network

Each square shows what one neuron responds to across the plot. Lines are weights: blue = positive, orange = negative, thicker = stronger.

What you're looking at

Each dot is a training example with two numbers (its x and y position) and a label (blue or orange). The network's job is to learn a function that takes a position and predicts the colour. The shaded background is the network's current prediction for every point on the plot. Deeper blue or orange means it is more confident, and white means it is unsure. That white band is the decision boundary.

How a neural network learns

  • Forward pass: each neuron computes a weighted sum of its inputs plus a bias, then applies an activation function (ReLU, tanh or sigmoid). The output neuron uses sigmoid to give a probability from 0 to 1.
  • Loss: binary cross-entropy measures how wrong the predictions are. Confident wrong answers are punished heavily.
  • Backpropagation: the chain rule works out how much each weight contributed to the loss, from the output layer back to the inputs.
  • Gradient descent: every weight takes a small step against its gradient. The size of that step is the learning rate. One pass over all the training data is an epoch.

Experiments to try

  • XOR with 0 hidden layers. A single neuron can only draw a straight line, so it fails. Add one hidden layer with 4 neurons and it succeeds. This is why we need hidden layers.
  • Activation = linear. Stack 4 layers and it still can't solve the circle. Without a non-linear activation, any number of layers collapses into one straight line.
  • Learning rate 3 or 10. The loss jumps around or explodes. Then try 0.001 and see how slowly it learns.
  • Spiral. From x and y alone this is genuinely hard: 3 layers of 8 neurons need thousands of epochs (set Speed to 20). Now tick sin x and sin y and a small network solves it in a few hundred epochs. Good features can matter as much as a bigger model.
  • Overfitting. Set noise to 50%, use a big network and watch the test loss rise while the train loss keeps falling. Add L2 regularisation to smooth the boundary.

Is this a real neural network?

Yes. It is a multi-layer perceptron written from scratch in plain JavaScript. Each epoch runs a forward pass, measures binary cross-entropy loss, backpropagates the gradients and updates every weight with mini-batch gradient descent, all on your device. Nothing is sent to a server.

Why can't the network solve the spiral?

Two inputs and one small hidden layer can only draw simple boundaries. Add more layers and neurons, switch to tanh, or tick the extra features (x², y², sin) to give the network more to work with. That trade-off between model capacity and feature engineering is a core idea in machine learning.

What do the small squares in the network diagram show?

Each square is the output of one neuron across the whole input space. Early neurons learn simple splits. Later neurons combine them into curves, and the output neuron combines everything into the final decision boundary.

Who is this for?

Students, interns and anyone preparing for a machine learning interview who wants to build intuition for layers, activations, learning rate, overfitting and backpropagation before reading the maths.

More Learn AI