Multilayer Perceptrons and Backpropagation › Visualizing Multilayer Perceptrons
Machine Learning from ScratchAll chapters 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
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]Expand

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]Expand
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]Expand

VisualizationOut [20]Expand

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 parameters and a linear log-odds surface. The MLP has 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!