- Published on

# Machine Learning Part 4: Maximum Likelihood Estimation

There's another way we can approach linear regression and that's from a probabilistic point of view. If you've ever dealt with logistic regression or neural networks then you've probably heard of maximum likelihood estimation. It's another way to estimate the parameters of our model. The goal of this blog post is to introduce maximum likelihood estimation and show how it's equivalent to estimating parameters using mean-squared error. First, let's start with a small review of some relevant probability concepts.

## Probability Review

Probability is the formal study of uncertainty. The sample space, $\Omega$, is the set of all possible outcomes of an experiment. For example, the sample space of tossing a die is

In our probability space, we have a probability distribution, $P$, that maps an event to a value between 0 and 1. A random variable, $X$, represents the outcome of an event.

The above represents the distribution of a variable and is read "Probability of random variable X taking on a value of A". For example, the probability of tossing a dice and getting a 5 is

The distribution of more than one variable is known as the joint distribution or joint probability.

For example, let's say we have two separate dice. What is the probability of rolling a 3 with dice 1 and rolling a 4 with dice 2?

The conditional probability is the probability of event $A$ occurring given that event $B$ has occurred.

Given two dice are rolled, what is the probability that one of the die is 5 given that the total sum is 10?

Let's first think about the probability of the total sum being 10 ($P(B)$). I can roll either {5,5}, {6,4}, or {4,6}. There are 36 total outcomes of rolling two die and 3 of them result in a sum of 10. Therefore, $P(B)=3/36$. Now, for the joint probability what is the probability of one of the die being a 5 AND the total sum being 10? This is simply the probability of rolling a {5,5} which is 1/36. Plugging these probabilities into our formula we have

The probability of rolling a 5 given the total sum is 10 is 1/3.

If $A$ is an independent variable, then the probability of a given event, $B$, has no effect on its outcome.

The marginal probability is the probability of a certain variable while summing out all other variables.

The expectation, $E(X)$, is the expected or average value of the variable $X$.

What is the expected value of rolling a die? We have

Bayes' theorem is used to calculate the probability of an event, given prior information related to the event.

The $P(X|Y)$ term is known as the posterior probability. We want to know the outcome of $X$, given the evidence from $Y$. The $P(Y|X)$ term is called the likelihood. It's the probability of seeing the evidence $Y$ for a particular outcome $X$. Bayes' theorem can also be written as

Where the probability $P(Y)$ is written in its full form.

## Maximum Likelihood Estimation

Before getting into maximum likelihood estimation, I want to talk about the two major schools of thought in probability: frequentist and bayesian. In frequentist reasoning, we apply probabilities to data and assume our parameters are not random variables. In bayesian thinking, we assign probabilities to hypotheses and consider our parameters as random variables. In terms of linear regression, the parameters are the weights. In maximum likelihood estimation, we use a frequentist approach and assume our data comes from a probability distribution and estimate our weights.

When estimating our weights, our objective was to minimize the mean-squared error loss function. In maximum likelihood estimation, we try to find the parameters that maximize a likelihood function to our data. Let's say we want to fit a linear regression model

Where the $\epsilon$ term is the noise which we will assume has a mean value of 0. We're also going to assume that our data comes from a normal distribution. The normal distribution is given by the following formula.

$\sigma$ is the standard deviation and $\mu$ is the mean. The probability distributions of our parameters are

Where

The output, $y^{(m)}$, is assumed to be normally distributed with a mean of $\mathbf{w}^T x^{(m)}$. We want to find the parameter, $\mathbf{w}$, that maximizes the fit of our probability distribution $P(y^{(m)}|x^{(m)})$ to our data. In math terms, we want

where $D = \left \{(x^{(m)}, y^{(m)}) \right \}_{m=1}^{M}$ is our data. The above is the definition of maximum likelihood estimation. We assume that each $y^{(m)}$ is only dependent on its respective $x^{(m)}$ so we can write each probability as a respective product (joint probability)

We replaced $P(D;w)$ with the likelihood function which is the product of the probabilities of each data point. We want to maximize this function. We can multiply the sum of products by log to get a regular sum since $log(AB) = log(A)+log(B)$.

The log cancels out the exponent so we can further reduce the above expression.

We can replace our constant in front with simply $M$

We can get rid of the negative sign by changing $argmax$ to $argmin$.

We can see that the above expression is equivalent to the mean-squared error. Thus we've shown that minimizing the mean squared error is the same as maximizing the likelihood function assuming our data is normally distributed.