The primary goal of machine learning is to leverage machine intelligence to derive an appropriate answer to a given question or task. Mathematically, the true relationship between a family of questions and their corresponding answers would be a composition of several hidden, unknown, and non-elementary functions.
Hence creating a universal engine capable of solving any type of task is highly challenging and nearly impractical—although reasoning LLMs have recently shown promising progress in this direction. As a result, different approaches are typically employed to address specific types of tasks. One common approach is supervised learning, which is well-suited for scenarios where the desired output varies systematically with changes in the input. 1
Given a set of data points and , our goal is to construct a model that learns a function that nicely predicts (or helps to predict) the corresponding output from input . Our data and are often fixed-dimensional vectors of numbers, i.e. and for arbitrary numbers and . We usually focus on problems where is univariate ().
Terminology
- The inputs are also called features, covariates, or predictors.
- The outputs are also called labels, targets, or responses.
- A pair is called a training example, and the list of training examples is called a training set.
Regression vs Classification
Supervised learning tasks can be classified in two ways according to the nature of the output space .
Tasks where the output space is continuous are called regression problems. Linear regression is a popular method to solve regression problems.
Tasks where is a set of discrete labels (e.g. ) are called classification problems. Especially, if there are just two classes, often formulated as or , the task is called binary classification. Logistic regression, SVM, or LDA are examples of methods to solve classification problems.
Models, Training and Prediction
Now that we have our task specified, we need to find a way to solve it.
In practice, we first construct a parameterized model and then adjust the parameters based on chosen evaluation methods to make the model as close to the true function as possible. Afterward, we can use our model to answer arbitrary questions within the family that we began with. These processes are each called training and prediction.
Deterministic Models
Models in supervised learning refer to parameterized functions that can be used to derive the desired output from inputs. The most intuitive way to construct a model is to directly express the underlying function that maps the inputs to the outputs. These models are called deterministic models, in contrast to probabilistic models that give the probability distribution of the output given the input. Deterministic models are more intuitive as they directly give the desired targets as function outputs, while probabilistic models are more flexible and can capture the uncertainty in the mapping.
Let's first look over deterministic models. We use the notation to refer to a model parameterized by where is the input variable.
Training : Empirical Risk Minimization
The process of determining the optimal parameter values for a model is referred to as training, fitting, or learning (from the model’s perspective). Since our goal is to make the model closely approximate the true underlying function, we define a loss function which quantifies the discrepancy between the model’s predictions and the true function.
Loss functions in general will have the form of , where a pair of two vectors of same dimension from an arbitrary set will be given as an input, and an evaluation of their closeness will be derived as the output. Loss functions do not necessarily have to be symmetric, i.e. a change in the order of the inputs may give different outputs. For a supervised learning setup, and a specific and its estimate will be the inputs for the loss function.
Now we define a cost function, or the empirical risk as below to be the average loss over the entire training set.
Then our task converges to an optimization problem to find the parameters that minimize the empirical risk.
Prediction
After is found, we can use as a prediction of the corresponding label to .
Probabilistic Models
In many cases though, it is hard to perfectly determine the correct output given the input. This may be due to lack of knowledge of the input-output mapping (called epistemic uncertainty or model uncertainty), or due to intrinsic (irreducible) stochasticity in the mapping (called aleatoric uncertainty or data uncertainty).
In these cases, we decide to capture the uncertainty itself, by modeling the conditional probability distribution of the variables. This estimation can be done both on the inputs or outputs, and also in both cases where the variables are discrete or continuous.
If the variable of our interest is discrete, e.g. a class label in a classification task, we can set our model to take a data point as an input and return the probability mass of over the possible labels as an output. Therefore the probablity that equals to a specific label will be:
If we are to predict continuous variables, we can set our model to take a data point (from either or ) as an input and return the probability distribution of its counterpart as an output. Generally we design our model so that , i,e. we estimate the probability of given . These models are called discriminative, and we get the following conditional probability distribution:
In contrast, if , i.e. we estimate the probability of given , the model is called generative. Note that we are predicting not , so need not be continuous and this case will include classification problems too. Now our conditional probability distribution is:
It is also common to model only a portion of the distribution and fix other attributes. For example, in regression problems, it is common to assume the output distribution is a Gaussian. Here we can make only the mean depend on the inputs and assume the variance is fixed. The resulting model will look like:
Training : Maximum Likelihood Estimation (MLE)
Suppose we constructed a model that predicts the probability distribution .2 Say the model is parameterized by , then we can denote the distribution as . Intuitively, given a set of i.i.d. samples , we can say that the model is good if it assigns high probability to the actually sampled values of . In other words, the model should be built in a way to maximize the likelihood of the given samples. Mathematically, we define this likelihood3 as:
The second equality comes from the i.i.d. assumption of the samples. In practice, it is common to convert the maximization problem to a minimization problem and use the negative log likelihood as the loss function. The negative log likelihood is defined as:
The factor is added for convenience, to format the objective into a finite-sum optimization problem. Now our task converges to an optimization problem to find the parameters that minimize the negative log likelihood.
Training : Cross-Entropy Loss
As outlined above, a loss function measures the distance between two vectors of the same dimension. When the negative log-likelihood (NLL) is used as the loss function, a natural question arises: what kind of distance is it evaluating? Intuitively, since our model estimates a probability distribution, it seems plausible that represents a meaningful measure of the difference between the true distribution and the model’s estimation.
This intuition is supported by two key concepts: the Kullback-Leibler (KL) divergence and entropy. For simplicity, we will focus on discrete random variables for now. In the context of information theory, given probability masses , the entropy and cross-entropy are defined as follows:
The entropy of a probability distribution can be interpreted as a measure of uncertainty, or lack of predictability of the data drawn from the distribution. To make this precise, from an informational perspective, entropy corresponds to the expected value of the information content of a data source. The choice of the logarithm base may vary in different applications, e.g. will scale the factor to the unit of bits, and in this case the entropy measures the expected number of bits in a data set.
Meanwhile the cross-entropy of two probability distributions is in a similar form, but the difference is that it evaluates the expected information content of a data source (sampled from ) on a different distribution (). Analogous to the "bits" interpretation of entropy, the cross-entropy can be understood as a measure of the expected number of bits needed to compress data sampled from a distribution when using codes from another distribution .
Now the KL divergence is defined and can be expanded as the following.
Note that the KL divergence is the sum of the negative entropy and the cross-entropy. Based on the "bits" interpretation of entropy and cross-entropy, the KL divergence represents the extra number of bits required to encode data from one distribution using a coding scheme optimized for a different distribution. This, intuitively, serves as a measure of the divergence or distance between the two distributions: the farther apart the distributions are, the greater the extra number of bits required will be.
Now suppose is the empirical distribution of our interest and is our model. Then can be defined as the following, where we put a probability mass on the observed training data and zero mass everywhere else.
In this case where is discrete, represents the Kronecker delta. Also note that is independent to the parameter ; only relates to . Finally we can show the equivalence of maximum likelihood estimation and KL divergence minimization as the following.
Now our initial intuition that maximum likelihood estimation minimizes the distance between the true distribution and our model has been validated. Moreover, since minimizing the KL divergence has only involved the process of minimizing the cross-entropy, we can directly use the cross-entropy as a loss function, simply called the cross-entropy loss, as a more concrete and explicit formulation of for use in optimization.
The same can be shown for continuous random variables. For probability densities and , the entropy, cross-entropy, and KL divergence are defined as the following.
Again, suppose is the empirical distribution of our interest and is our model. This time is as the following, which is slightly different in that we use the Dirac delta function instead of the Kronecker delta.
Similarly, we can show the equivalence of maximum likelihood estimation and KL divergence minimization as the following:
Prediction
After is found, we can sample from the model to get the predicted output. For discriminative models, we can sample from the distribution to get the predicted label. For generative models, we can sample from the distribution to get the predicted input.
References
Footnotes
-
Some other widely used approaches are unsupervised learning and reinforcement learning. Together with supervised learning, these three are the most common paradigms in machine learning. The target tasks of each method can be described in the following format.• Supervised LearningText in blue indicates the desired output for the task, and text in brackets represents elements that may vary depending on the specific task. ↩
Produce [output] satisfying [condition] relative to [input], given collection of ([input], [output]) pairs.
• Unsupervised LearningProduce [output] satisfying [condition], given collection of possible [output]s.
• Reinforcement LearningFind the optimal next action to perform in a [single|multi]-state environment, given rewards and [∅|transitions].
-
In Bayesian statistics, the likelihood is defined as the probability of the variable of our interest given a variable with prior knowledge. In this case, the likelihood is the probability of the observed data given the parameters of the model, i.e. we are using and interchangeably. ↩