Linear Discriminants

See the easiest example: Two class classification

  • Get class labels as a function of the features:
  • Discriminant:
  • Linear classifier is a linear function of .

From a geometric view, the slope is determined by , offset from origin by i.e. .

flow 1
flow 2

For convenience, fold the bias in and . So that . The hyperplane equation becomes . We use to denote from now on.

  • Modify classify a new datapoint
  • Modify change the discriminant

Choosing a good classifier

  • Minimize misclassified training points
  • Maximize separation of the most ambiguous points
  • Maximize data probability

If we generalize to classes, simply combine multiple 2-class classifiers, and watch out for ambiguous regions. The result depends on the slope , not just the decision itself.

  • use

Explanation

The boundary between regions and is where :

This is itself a hyperplane, with normal vector . There we have it. The boundary’s orientation depends on the difference of the two weight vectors, not on either one alone.

  • The norm matters because each individual discriminant doesn’t move if we rescale , but the pairwise boundary becomes
    • As changes, the normal rotates (unless perpendicular)

Tiny numeric example (2D, 2 classes)

We have , (i.e. ) and , (i.e. )

Boundary is at the slope equals 1.

Now scale by , so . The boundary now moves to the slope equals 2.

Linear Perceptron

Inspired by the brain: binary signal, multiple inputs one output, fires if activation is high enough.

The activation is defined by a non-linear step function:

The training dataset uses the target coding scheme:

Training via stochastic gradient descent

Classification is correct if and only if:

The objective is to minimize the misclassification rate , where is the set of misclassified examples.

We simply update the weights by bgd (batch gradient descent):

that’s the β€œstochastic” part β€” one misclassified example per update rather than the full batch. It reads as β€œwhenever you hit one that’s misclassified, nudge in the direction of scaled by . Repeat until no misclassifications remain.”

Mini-batch gradient descent minimizes the function by summing the gradient over a subset of datapoints (according to the lectures). Applied to the perceptron learning rule, this means the weights update is calculated using a small sample of the misclassified examples , rather than the entire batch or a single occurence. It could provide a more stable error update than SGD while remaining computationally faster than full batch gradient descent

Perceptron Convergence Theorem

If the training set is linearly separable, the algorithm is guaranteed to find a solution in a finite number of steps.

Problems with perceptrons

  • slow, doesn’t generalize past 2 classes, no way to tell β€œnot separable” from β€œslow to converge”, not guaranteed to reduce error every step (the set of misclassified training examples changes at each weight update), solution depends on initial conditions.

Gradient Descent flavors

  • Batch: sum over all data points
  • Stochastic: approximate with one random point at a time β€” fast, avoids bad local optima, handles redundancy; but noisy, messier stopping criterion
  • Minibatch: sum over a subset

See SGD.

Probabilistic Models

they can deal with missing data, include prior knowledge and uncertainty in our parameter values. Confidence comes as a prediction.

Generative Probabilistic Models

Learn the point , classify via Bayes’ rule:

  • it’s optimal as long as the true distributions are learned correctly as .
  • for certain distributions, the model results in linear classification.
    • an example would be normal distributions with shared covariances: .

Demonstration

The decision boundary between two classes and occurs where their posterior probabilities are equal:

For a multivariate Gaussian distribution with class mean , shared covariance matrix , and input feature dimension (where ):

Taking the logarithm:

Because all classes share the exact same covariance , the quadratic term and the normalization constants are identical.

Subtracting the log-likelihoods cancels out the quadratic component completely:

Setting the log-posterior ratio to zero yields a purely linear boundary :

Discriminative Probabilistic Models

  1. We directly optimize instead of modelling . They model the posterior distribution for a two-class problem as a sigmoid (goes from 0 to 1, and at , we go through 0.5).
  1. For classes, the posterior is a softmax function: :

To derive the -class posterior, start with Bayes’ theorem to find the probability of class given data :

Expand the marginal probability in the denominator over all possible classes using the law of total probability:

Define the activation as the natural logarithm of the joint probability:

Take the exponential of both sides to express the joint probability in terms of :

Substitute this exponential form into both the numerator and the sum in the denominator to yield the final softmax function for classes:

for 2 classes sigmoid, for K-classes softmax.

Generative vs. Discriminative

Generative models learn the distribution of the data:

  • can sample/generate data
  • optimal if known true distribution

Discriminative models directly optimize :

  • a is linear in case of normal distributions with shared covariances
  • more robust when true distributions are unknown
  • requires more data.

Logistic Regression

We wrote the posterior probability of the class given a datapoint as:

The parameters of this model, , can be trained by conditional Maximum Likelihood:

This is equivalent with minimizing the binary cross-entropy loss. Taken from Contextual Word Embeddings and Transformers.

Basis Functions

Linear models might be restricted, but they are cheaper to train and less prone to overfitting due to their few adjustable parameters.

We keep the advantage of the classifiers and extend to non-linear problems by transforming the features:

β€œLinear” here means linear in parameters, not in data.

The model is still calculating a simple weighted sum using the parametersΒ w, which makes it mathematically a linear model that is easy to train and less prone to overfitting. However, instead of applying these weights to the raw dataΒ , it applies them to the transformed featuresΒ . This means the model is no longer linear with respect to the original input space, allowing it to capture complex, non-linear patterns while keeping the underlying parameter optimization simple.

Gaussian basis functions reshape the feature space to make the classes separable

No single straight line can successfully split the two groups in the left image. By feeding this raw data through non-linear Gaussian basis functions centered at specific points like ​ and ​, the data is projected into an entirely new coordinate system defined by ​ and ​.

This mathematical transformation warps the space so that the red dots cluster together at the top and the blue dots group at the bottom (right image). Once the data is reshaped into this new space, a standard linear classifier can easily draw a straight line to separate the classes.

Regularization (dealing with overfitting)

The problems are:

  1. more basis functions more parameters risk of overfitting
  2. lacking the right basis functions insufficiently flexible model (underfitting)

If we revisit the polynomial regression (rewrite as basis function) example where we try to fit the sin function where the observations are corrupted by Gaussian noise and we minimize the error function:

We observe that increasing the model complexity , we overfit the noise.

So we add a penalty term depending on the model. Typically, we want to penalize the larger parameters values.

  • must be set independently, and it basically answers β€œhow much do you trust the data?”

Notes about Regularization

Leave out of the penalty term. Shifting the data should not affect the model’s performance.

Square penalty or -norm leads to simple optimization and it’s called ridge regression (stats), weight decay (NNs). It shrinks weights toward zero, spreading influence across correlated features instead of letting one spike.

Closed form: . Always invertible for .

norm cannot be optimized in closed form and it leads to sparse solutions (some ).

Lasso: penalize norm, prefers sparse solutions.

The ball has corners on the axes. The squared-loss contours first touch it at a corner (with high probability), and a corner means some coordinates are exactly zero. That is why Lasso does feature selection while ridge does not.

norm

How to read the figures

  • The axes are the two weights, and . Every point in the plane is one possible model.
  • TheΒ ellipsesΒ are iso-lines of the error: all points on one ellipse fit the data equally well. The center, , is the unregularized best fit. Further out means a worse fit.
  • TheΒ circle/diamond/starΒ is an iso-line of the penalty: all weight vectors with the same penalty. The penalty is smallest at the origin (all weights zero).
  • Β is the regularized solution. You want the lowest error (the smallest ellipse) while staying within your penalty budget (inside the shape). That happens where the growing ellipse first touches the penalty shape.

So regularization is a tug-of-war: the error pulls you toward , and the penalty pulls you toward the origin. is the compromise.

qShapeEffect
2circleshrinks all weights smoothly, closed form
1diamondsparse, convex, no closed form
< 1stareven sparser, non-convex (hard)

And the difference exactly between and ?

The difference comes down to how the penalty treats small weights.

Gradient (the β€œpull” toward zero)

  • L2: pull = . It is proportional to the weight, so as w gets small, the pull fades. A weight gets close to zero but never quite reaches it.
  • L1: pull = . It is a constant push regardless of how small is, so it can drive a weight all the way to exactly zero.

Geometry (the figures)

  • L2: circle, no corners, so the solution lands at a generic point where all weights are nonzero.
  • L1: diamond, corners on the axes, so the solution often lands on a corner where some weights are exactly zero.

Correlated features:Β with two nearly identical features, splits the weight between them, while tends to pick one and zero the other.

What if is too large?

It will cause underfitting regardless of the regularization applied. Because the penalty term in the equation drives the weights towards the origin (0). L1 will actually allow values of 0 while L2 avoids it, but keep them small enough. So that will mean underfitting since overfitting is essentially high values of weights, or that’s at least one way to detect it.

Intuitively, a too small barely contributes with anything. So the objective function (error term) will grow the weights as large as it needs to fit the training data as closely as possible. It makes absolute sense since they are methods of avoiding overfitting.

Bishop, p. 181-182, 192-196, 196-201, 204-206