Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Defining Binary Classification

Hello! Welcome to the first lesson in our new module on classification.

In our previous module, we completed a thorough investigation of linear regression. We learned how to model problems where the goal is to predict a continuous numerical value, derived the OLS and Ridge regression solutions, and analyzed their statistical properties like bias and variance.

Today, we shift our focus from regression to classification. This is a vast and fundamental area of machine learning concerned with predicting discrete, categorical labels rather than continuous quantities. Our learning outcome for this lesson is to formulate the binary classification problem mathematically. We will define the components of the problem, establish the notation we'll use throughout this module, and understand why the methods we learned for regression are not directly suitable for this new task.

1. What is Classification?

In regression, we predict a quantity (e.g., house price, temperature). In classification, we predict a category (e.g., spam/not spam, malignant/benign tumor, fraudulent/valid transaction). The simplest and most common type of classification is binary classification, where there are only two possible outcome categories.

Let's begin by watching a short introduction from Professor Trevor Hastie, one of the authors of the seminal textbook "The Elements of Statistical Learning," who will contrast classification with regression.

Statistical Learning: 4.1 Introduction to Classification Problems

This video introduces the core idea of classification, provides real-world examples, and defines a classifier from a mathematical standpoint.

Please watch the first two minutes of the video (00:00 - 02:04). Pay close attention to how a classifier is defined as a function c(x) that maps a feature vector x to a value in a discrete set C.

As the video explains, the goal is to build a function, a classifier, that takes a feature vector as input and outputs a predicted class label.

2. Can We Use Linear Regression for Classification?

A natural first question, given our extensive study of linear regression, is whether we can adapt it for classification. For a binary problem, we could encode the two labels as 0 and 1. For example, y = 0 for "benign" and y = 1 for "malignant". We could then perform a linear regression of y on our features X. To make a prediction, we could check if the predicted value is greater than a threshold, like 0.5.

While this seems plausible, it introduces significant problems. The following video clips explain why this approach is flawed.

Statistical Learning: 4.1 Introduction to Classification Problems

This video from the Stanford Online course explains why linear regression is not ideal for classification tasks. It highlights two key issues.

Please watch the segment from 06:22 to 10:25. Focus on the two main criticisms of using linear regression for classification: 1) the model can produce predictions outside the [0, 1] range, and 2) the arbitrary numerical coding for multi-class problems implies a non-existent ordering.

The key takeaways are:

  1. Meaningless Predictions: A linear model can produce any real number, but for a binary (0/1) problem, we are trying to model something that should behave like a probability. A predicted "probability" of 1.3 or -0.2 is nonsensical.
  2. Artificial Ordering (in multi-class cases): If we have three classes (e.g., "stroke," "overdose," "seizure") and code them as 1, 2, and 3, linear regression would incorrectly assume that the "distance" between stroke and overdose is the same as the distance between overdose and seizure.

These issues make it clear that we need a different mathematical framework, one designed specifically for modeling categorical outcomes.

3. The Formal Mathematical Formulation

Let's now build the precise mathematical formulation for binary classification, which will serve as the foundation for the rest of this module. Your background in mathematics and programming will be helpful here as we define the data structures and objectives formally.

We will base our formulation on the definitions provided in the lecture notes from MIT's "Mathematics of Machine Learning" course.

Mathematics of Machine Learning Lecture 1 Notes

These lecture notes provide a concise and rigorous definition of the binary classification problem.

Please read the section '2.1 Binary classification' on page 2. Focus on understanding the definitions of the observed data (X, Y), the feature space X, the label space {0, 1}, the classifier h, and the regression function η(X).

Let's synthesize and expand on the key definitions from the reading.

  • Data: We assume we have a dataset of independent and identically distributed (i.i.d.) observations:
  • Feature Space (): Each input is a feature vector, which is an element of the feature space . In most ML applications, this is a -dimensional Euclidean space, so .
  • Label Space (): Each output is a label. For binary classification, the label space consists of just two values, which by convention we denote as .
  • Classifier (): The goal is to learn a function, called a classifier or hypothesis, that maps the feature space to the label space: This function takes a new, unseen feature vector and predicts its label, .

Visually, you can think of a classifier as creating a decision boundary in the feature space that separates the data points of one class from those of the other.

Binary Classification Problem with Decision Boundary
This image illustrates a binary classification problem in a 2D feature space (\(x^{(1)}, x^{(2)}\)). The classifier's job is to find a decision boundary (like the dashed line) that effectively separates Class 0 points from Class 1 points.

4. A Probabilistic Approach

Simply predicting a label (0 or 1) is useful, but often it's more valuable to know the model's confidence in its prediction. For instance, in medical diagnosis, knowing a tumor has a 98% probability of being malignant is more informative than just a "malignant" label, as it suggests a higher urgency than a 51% probability.

This leads to a more nuanced and powerful formulation of the classification problem: instead of learning a direct mapping to , we aim to model the conditional probability that the label is 1, given the features.

As defined in the MIT notes, we introduce the regression function :

This expression is the cornerstone of probabilistic classification. It states that for a given feature vector , there is a specific probability that the corresponding label is 1.

Under this view, the label itself is a random variable that follows a Bernoulli distribution, with its parameter given by .

This is a precise mathematical statement of our assumption about the data-generating process. It elegantly captures the idea that even for the exact same features , the outcome might not be deterministic due to inherent randomness or unobserved factors (this is what the notes refer to as "noise").

Our objective now shifts from learning the classifier directly to learning the probability function . If we can find a good approximation of , we can easily create a classifier by applying a threshold. The standard choice is 0.5:

Test your understanding!

In linear regression, we modeled the target as , where we assumed . In binary classification, we model . How are the error term in linear regression and the probabilistic nature of in classification related concepts?

Show answer

Both concepts account for the fact that the features do not perfectly determine the output .

  • In linear regression, the error term represents the deviation of an individual observation from the conditional mean, . It models noise and the effect of unobserved variables.

  • In classification, the probabilistic formulation inherently acknowledges uncertainty. If , it means that even with the given features , there's still a 20% chance of observing . This uncertainty is analogous to the noise captured by in regression. In both cases, the model acknowledges that is not a deterministic function of .

Conclusion

In this lesson, we have formally defined the binary classification task, distinguishing it from the regression problems we studied previously. We established the precise mathematical language and notation required for a rigorous analysis.

Key Takeaways:

  • Classification vs. Regression: Classification predicts a discrete category, while regression predicts a continuous value.
  • Failure of Linear Regression: Applying linear regression to a 0/1 coded classification problem is flawed because it can produce predictions outside the meaningful [0, 1] range and doesn't naturally handle the probabilistic nature of class labels.
  • Formal Formulation: A binary classification problem involves learning a classifier from a dataset of feature-label pairs .
  • Probabilistic View: A more powerful approach is to model the conditional probability . This reframes the learning problem as finding a function that maps features to a probability in the interval .

Preview of the Next Lesson:
We have established that our goal is to model the probability . We need a function that takes our familiar linear combination of features, , which can produce any real number, and maps it to the interval required for a probability. In the next lesson, we will derive the logistic (sigmoid) function and explore its properties, showing why it is the perfect candidate for this task.

Can't find a good explanation? Sign up and we'll make it for you

Sign up