Deep Learning 1 - Single-Layer Models
Welcome - pull up a chair. A single-layer model is the smallest useful laboratory for deep learning. There is nowhere for the mathematics to hide: we can see exactly how an input becomes a prediction, how a loss turns an error into a number, and how a gradient tells every parameter which way to move.
We will begin with regression, where the target is a number. Then we will ask whether a richer feature map actually generalizes beyond the training set. Finally, we will reuse the same linear score for binary and multiclass classification. That progression matters: linear regression, logistic regression, and softmax regression look like separate algorithms only until we identify their shared structure.
Single-Layer Models
A single-layer model maps an input directly to an output without any hidden layers. Linear regression is the simplest example: it combines the input features linearly and adds a bias term.
Linear Regression
For an input vector
where
Loss Function and Cost Function
For one training example with prediction
The factor
The loss measures the error on one example, while the cost aggregates the losses over the entire dataset.
Vectorized Form
Stack the input examples as rows of the design matrix
Let
The cost function becomes
Vectorization avoids writing a separate prediction equation for every example and allows efficient matrix operations.
Partial Derivatives
For a function of multiple variables, a partial derivative measures the change with respect to one variable while keeping the others fixed. For example,
For the linear regression model
the local derivatives are
Chain Rule
The loss depends on a parameter through the prediction
and
These equations show that the gradient is the prediction error multiplied by the sensitivity of the prediction to the parameter.
Gradients over the Dataset
After averaging over all
and
In vector form,
Gradient Descent
Gradient descent repeatedly moves the parameters in the direction opposite to the gradient. For each weight,
and the bias is updated by
The vector update is
Here
For linear regression, a direct closed-form solution is possible, but it can require a matrix inversion with roughly
Polynomial Regression and Feature Maps
A model can be nonlinear in the original input while remaining linear in its parameters. For a scalar input
Then polynomial regression can be written as
The feature map changes the representation of the input. Once the transformed features are constructed, the same linear regression loss, gradient calculations, and optimization procedure can be used.
The model is nonlinear as a function of the original input
Generalization
Training fit is not the final goal
Suppose we observe noisy samples from a smooth curve. A constant model cannot follow the trend and a degree-one line may still miss important curvature. A degree-three polynomial might capture the broad pattern. A degree-nine polynomial may pass almost exactly through every training point while oscillating violently between them.
These are two different failure modes:
- Underfitting: the hypothesis class is too restricted to explain even the training data.
- Overfitting: the model adapts to accidental details of the training sample and performs poorly on new data.
The aim is therefore not
but rather
This ability is generalization. A small training loss is evidence that optimization worked on the data we supplied; it is not, by itself, evidence that the learned relationship will survive outside that sample.
Parameters and hyperparameters
The coefficients
If we choose
- The training set determines model parameters.
- The validation set compares hyperparameter choices and training decisions.
- The test set is held back for a final, less biased estimate of performance.
The validation set is part of model development. Repeatedly adjusting a model after looking at test performance gradually turns the test set into another validation set.
Key idea: optimization asks, “Which parameters fit this training objective?” Generalization asks, “Did we choose a model and training procedure whose success transfers to data we did not fit?”
Binary Classification
From a score to a decision
In binary classification the target is discrete, usually
A hard classifier could threshold this score:
The boundary
Logistic regression
Instead of optimizing the thresholded decision, logistic regression passes the logit
The model is
Because
The name logistic regression is historical. Despite “regression,” its usual purpose here is classification. It is also called a log-linear model because the log-odds are linear:
Cross-entropy loss
For a Bernoulli target, binary cross-entropy is
When
Cross-entropy is not an arbitrary smooth replacement for accuracy. It is the negative log-likelihood of a Bernoulli model and a proper scoring rule: in expectation, the best reported probability is the true conditional probability.
The sigmoid and cross-entropy simplify beautifully. Since
the chain rule gives
The same “prediction minus target” term that appeared in linear regression reappears at the logit. The weight gradient is
This is one reason activation and loss are usually treated as a matched pair.
Multiclass Classification
One-of- targets and a matrix of weights
For
with the
The components of
Softmax
Softmax converts the logits into a probability vector:
$$
y_k=\operatorname{softmax}(\mathbf z)k
=\frac{e^{z_k}}{\sum{r=1}^{K}e^{z_r}}.
$$
Every
For numerical stability, implementations subtract
For two classes, softmax depends only on the logit difference and reduces to a sigmoid. If
Binary logistic regression is therefore the two-class special case of multiclass logistic regression.
Softmax cross-entropy
With a one-hot target, multiclass cross-entropy is
Only the correct class contributes directly because only one target entry is 1. Combining softmax and cross-entropy again yields a compact derivative:
Consequently,
The outer product has shape
One Pattern Behind Three Models
The three single-layer models now line up:
| Task | Linear score | Activation | Loss | Logit-level error |
|---|---|---|---|---|
| Scalar regression | Identity | Squared error | ||
| Binary classification | Sigmoid | Binary cross-entropy | ||
| Multiclass classification | Softmax | Multiclass cross-entropy |
Each model first forms an affine score, then uses an output transformation appropriate to the target, then compares the prediction with the target using a compatible loss. Gradient descent propagates the resulting error into the parameters.
This shared pattern is the bridge to neural networks. A multilayer network will replace the hand-designed feature map
- Title: Deep Learning 1 - Single-Layer Models
- Author: Gavin0576
- Created at : 2026-09-10 02:04:18
- Updated at : 2026-10-23 19:41:29
- Link: https://jiangpf2022.github.io/blog/2026/09/10/Columbia-Neural-Networks-Deep-Learning/
- License: This work is licensed under CC BY-NC-SA 4.0.