Multilayer Perceptrons and Backpropagation › Visualizing Multilayer Perceptrons

Michael BrenndoerferOctober 29, 20265 min read
Machine Learning from ScratchAll chapters
Part 7 of 15Supervised Learning Beyond Linear Models
Chapter 57Multilayer Perceptrons and Backpropagation › Visualizing Multilayer Perceptrons
Reading section 7 of 10 · Visualizing Multilayer Perceptrons · 5 minSection 7 of 10 · 5 min

Section 7 of 10 · 5 min read

Multilayer Perceptrons and Backpropagation › Visualizing Multilayer PerceptronsSection view · Sections in this chapter7 / 10 ↓
Reading tools Definitions, links & notes

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Notes & comments

The training curve shows the regularized full-training-set objective after each mini-batch epoch. Since updates use different mini-batches, this monitored objective need not decrease at every epoch. The displayed decrease describes the optimization run; judging model capacity and stopping time also requires validation results.

VisualizationOut [17]
CollapseExpand
A line chart with epoch on the horizontal axis and regularized training loss on a logarithmic vertical axis. The training loss falls rapidly at first and then flattens.
Mean training binary cross-entropy plus the L2 weight penalty across mini-batch epochs, plotted on a logarithmic scale. The objective decreases quickly at first and then more slowly; this training curve alone does not establish validation performance or convergence to a global minimum.

The next two figures compare the decision boundaries of logistic regression and the trained MLP on the same standardized test data. The first shows the logistic boundary, which is constrained to be a straight line in the input space. The second shows the MLP, which can bend its boundary because the hidden layer transforms the inputs before the output layer makes its decision. On a two-moons problem, this flexibility is exactly what allows the network to represent a curved decision region.

The decision-boundary figures build a probability grid over the feature space for both models before plotting, so the plotting cells below contain presentation logic only. The logistic panel shows the strong linear constraint of logistic regression, while the MLP panel shows a curved boundary that can bend to follow the crescent shapes.

PythonIn [18]
CollapseExpand
xx, yy = np.meshgrid(
    np.linspace(Xte[:, 0].min() - 0.5, Xte[:, 0].max() + 0.5, 200),
    np.linspace(Xte[:, 1].min() - 0.5, Xte[:, 1].max() + 0.5, 200),
)
grid = np.c_[xx.ravel(), yy.ravel()]

s_grid, _ = forward(params, grid)
p_mlp_grid = sigmoid(s_grid).reshape(xx.shape)
p_logit_grid = logit.predict_proba(grid)[:, 1].reshape(xx.shape)
VisualizationOut [19]
CollapseExpand
Scatter plot of two interleaving crescent-shaped classes with a nearly straight decision boundary from logistic regression.
Decision boundary of logistic regression on the two-moons test set. Shading indicates the predicted probability of class 1, and the contour marks the 0.5 threshold. The linear constraint keeps the boundary nearly straight, so the interleaving crescents cannot be cleanly separated, which motivates the nonlinear MLP.
VisualizationOut [20]
CollapseExpand
Scatter plot of the two crescent-shaped classes with a curved MLP decision boundary that follows the crescents more closely.
Decision boundary of the one-hidden-layer MLP on the two-moons test set. The curved boundary follows the crescent shapes more closely than the linear baseline, showing how the hidden layer adds representational flexibility and can separate a curved region rather than a single straight cut.

The comparison illustrates the role of the hidden layer. The MLP boundary bends to follow the two moons more closely than the linear baseline does, which is consistent with the hidden layer providing the representational flexibility to represent a curved region on this task. This graphical observation is distinct from the earlier single-split test metrics, and it does not by itself establish that the MLP has better generalization performance than the linear baseline. The logistic model has d+1d+1 parameters and a linear log-odds surface. The MLP has h(d+1)+h+1h(d+1)+h+1 parameters and can represent a much richer family of surfaces. That added capacity is not automatically better: with too little data, too much noise, or too little regularization, the MLP can fit idiosyncrasies of the training set. A validation split can guide capacity and regularization choices when tuning; that selection step is not implemented in this example, which uses prespecified hyperparameters.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy