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 sgd:

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.”

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

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.

Basic 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.

Complete from slide 37/41.