# Chapter 3 – Cross Entropy

# Chapter 3 – Cross Entropy#

Data Science and Machine Learning for Geoscientists

The problem of the Maximum Likelihood approach in the last chapter is that if we have a huge dataset, then the total Prob(Event) will be very low (even if the model is pretty good):

This is a maximum likelihood approach for a `10 students’ prediction. This prediction is just as good as the previous one, but the total Prob(Event) is significantly lower than the previous one. To solve this problem, we can use natural log:

So for the first AI, we have:

According to tradition, we choose the magnitude of the result: 4.086.

For the second AI prediction, we have:

The lower the score is, the better the prediction. This score is known as the cross-entropy, which can be expressed as follow:

where \(y_i\) is the actual result (0 or 1), representing if the \(i^{th}\) student got accepted or rejected; and \(p_i\) is the prob(event) for the \(i^{th}\) student.

The first part of the equation means how good the AI predicts the students who got accepted; the second part the equation evaluates how well AI predicts the students who got rejected.`

Another reason for using the cross entropy is the concern of low learning speed caused by the flattened gradient (http://neuralnetworksanddeeplearning.com/chap3.html#eqtn6). Using the cross entropy format should have higher gradient and solves the problem.

Notice that we do have another form of cost: the quadratic cost.

When should we use the cross-entropy instead of the quadratic cost? In fact, the cross-entropy is nearly always the better choice, provided the output neurons are sigmoid neurons. To see why, consider that when we’re setting up the network we usually initialize the weights and biases using some sort of randomization. It may happen that those initial choices result in the network being decisively wrong for some training input - that is, an output neuron will have saturated near 1, when it should be 0, or vice versa. If we’re using the quadratic cost that will slow down learning. It won’t stop learning completely, since the weights will continue learning from other training inputs, but it’s obviously undesirable.