## Linear Regression from Maximum Likelihood View

Hi everyone! In this post, we will discuss a very simple subject, particularly for those who has been studying machine learning: linear regression. However, we will try to cover it from the maximum likelihood angle of view. Hopefully this can give you some intuition of how linear regression objective function could be derived.

You should be pretty familiar with mean-squared-error function which linear regression setup tries to minimize. Namely: \[ \begin{aligned} \mathcal{E}(w) = \frac{1}{2} \sum^n_{i=1} \big( f_w(x_i) - y_i \big)^2 \end{aligned} \]

Where is the true target value and is a linear function that parameterized by the weights we estimated from the data. Namely, , where is the feature map (if you’re not familiar with feature map, then simply regard just as regular ).

How one could justify this particular kind of error function?

We will start this argument by an assumption that our data are generated by some unknown true target function where , and some random noise for each data point . We then can formulate each target value as:

\[ \begin{aligned} y_i & = f_{\hat{w}} + e_i\newline & = \hat{w} * \phi (x_i) + e_i \end{aligned} \]

The second assumption is that each is i.i.d. and that it distributes according to some normal/gaussian distribution of certain variance and centered at 0:

\[ e_i \sim \mathcal{N}\big(0, \sigma^2 \big) \]

By this assumption, we now have the true target values also distributes by a normal distribution:

\[ y_i \sim \mathcal{N}\big(f_{\hat{w}}, \sigma^2 \big) \]

**Note:** and this sigma is shared among all .

One fundamental notion in statistics and machine learning that we will introduce here is likelihood function and maximum likelihood estimate. Likelihood function is the function of parameters , that measure the likelihood of the parameters given data . Turns out, the likelihood is equals to the probability that data is generated given parameters . Formally, likelihood function , maps parameter (vector) to a real number. In our case of linear regression, the likelihood function of is defined as follow:

\[ \begin{aligned} \mathcal{L}(w \mid D) & = P(D \mid w)\newline & = P(y_1,y_2,\dots,y_n \mid x_1,x_2,\dots,x_n, w) \end{aligned} \]

**Note:** in regression problem, are the observed variable and therefore we have as the condition in addition to .

The next important notion would be the maximum likelihood estimation. It simply defined as finding the set of parameters which gives the maximum likelihood given the data. We can denote the maximum likelihood estimate of as follow:

Now, recall our assumption that: . By this assumption, we can plugin a gaussian distribution formula into our maximum likelihood estimate equation. Namely:

Maximizing the above expression is equivalent to minimizing the negative logarithm of it. We do so to remove the exponential and make it more convenient to deal with this equation. We should now have:

Because we minimizing with respect to , the terms and log on the right becomes a constant that we can ignore. We finally multiply the expression with a constant to make it more convenient when taking the derivative of it.

Finally, we ended up with this expression that we need to minimize:

Voila! There we have the loss function that we really familiar with. And so, the take on lesson from this derivation is that finding the maximum likelihood estimate of is equivalent to minimizing the the sum-of-squares error.

You should also notice that we do use several assumptions in this derivation. In practice, these assumptions don’t always hold true. For example, the assumption of gaussian error distribution makes it very sensitive to outliers. In the next post, we shall show you why that is the case, and how regularization term could be justified to improve the model robustness to outliers.

See you in the next post.