Nowadays, there are a lot of tools and tutorials that help us use sophisticated mathematical concepts easily. These also bring machine learning and computer science to a large number of people. Moreover, they provide the ability to deal with this field without considerable background. I think that a lot of people might ask themselves *“why is it recommended to prefer a method over another?”* and *“where does this solution come out?”*. Well, I’m going to try to give you some tips to answer these questions.

It seems that there is a strong relationship between cross entropy and what we call likelihood! In the next paragraphs, I’ll try to explain this relationship.

** N.B. **In the article some concepts are not explained thoroughly so as to allow that everyone understands easily.

## Statistics and likelihood

Likelihood is the operation (function) that starting from parameters of a model gives as a result the probability that the input is associated with the reference value. To introduce the likelihood we need to take some steps back.

By starting with some statistics basic notations we can define probabilities. Given two events we define the **prior** (or the known) **probability** of set X and a prior probability of set Y.

If there is an intersection between these sets we can define the intersection as **joint probability** of X and Y defined as . The first term on the right is the **conditional probability** of Y given X, that means, the probability that an event Y can happen given the event X. With more attention we can see that the joint probability depends on both sets, so we can also define it as . Ultimately, we obtain that the two probabilities are equals.

Now that we know about all probabilities previously explained, we should ask how the conditional probability is described:

- ;
- ;

Left term is called *Posterior Probability*, because we see it as the dependence by “opposite” conditional probability and the known probability of the other set. Denominator is called *Evidence *and it is the sum of the joint probabilities, but we don’t care about it, as a matter of fact, it is a normalization factor that for our case, can be removed. Putting all the previous elements together, we can summarize the last equation as:

.

What!? We found the likelihood! So it is time to compute this value! The main problem is that if we try to compute the joint probability, we must multiply all probabilities of all subsets, given all other subsets, and the event. It looks like:

- ;
- ;
- ;
- ;
- ;
- and so on…

It is not an easy task…To help us we can assume that all events are independent from each other and we can easily multiply them together! In this way the equation becomes:

In the end we are only interested in likelihood.

Now probabilities computation only depends on what kind of distribution we are interested in. It could be Normal distribution, Bernoulli, Poisson and so on. Eventually, there is a last problem: product is a wasteful operation, so it is possible to apply a function to likelihood. That function is the logarithm. In this way, all properties are preserved and, moreover, logarithm of products corresponds to their summation:

It is called ** log-likelihood**.

## Cross entropy loss function

As it was said in a previous post, a loss function is used to allow our models to learn and it gives us reasonable results in many tasks, such as classification and prediction. One of the most used function is the so-called *Cross Entropy*. It can be used in binary and in multi-class problems and it is formulated as:

where is the class label and is the prediction done by our hypothesis and it can be written as . This means that the output is obtained from a hypothesis function that tries to estimate the true value of . Estimation is the keyword! It refers to the operation to find a value for that is probably similar to . The right name for this kind of operation is ** likelihood**. Cross entropy is also called

**negative log-likelihood**.

How can we derive this function from the likelihood that we explained above? Without being too specific and make things easier, we address the problem easily by Bernoulli distribution, which its general form is:

When applied to likelihood, we can rewrite it as:

We used the “pure” likelihood so far, but also in this case, it is possible to apply logarithm; and thanks to the several logarithms properties we obtain:

Rewriting cross entropy with a generic equation, it follows:

We obtained the same function! Minus symbol is added for minimization purpose.