# How is logistic loss and cross-entropy related?

I found that Kullback-Leibler loss, log-loss or cross-entropy is the same loss function. Is the logistic-loss function used in logistic regression equivalent to the cross-entropy function? If yes, can anybody explain how they are related?

Thanks

The relationship between Cross-entropy, logistic loss and K-L divergence is quite natural and immersed in the definition itself.

Cross-entropy is defined as: $$H(p, q) = \operatorname{E}_p[-\log q] = H(p) + D_{\mathrm{KL}}(p \| q)=-\sum_x p(x)\log q(x)$$ Where, $p$ and $q$ are two distributions and using the definition of K-L divergence. $H(p)$ is the entropy of p. Now if $p \in \{y,1-y\}$ and $q \in \{\hat{y}, 1-\hat{y}\}$, we can re-write cross-entropy as: $$H(p, q) = -\sum_x p_x \log q_x =-y\log \hat{y}-(1-y)\log (1-\hat{y})$$ which is nothing but logistic loss. Further, log loss is also related to logistic loss and cross-entropy as follows:

Expected Log loss is defined as follows: $$E[-\log q]$$ Note the above loss function used in logistic regression where q is a sigmoid function. Excess risk for the above loss function is defined as follows: $$E[\log p - \log q ]=E[\log\frac{p}{q}]=D_{KL}(p||q)$$ Notice that the K-L divergence is nothing but the excess risk of the log loss and K-L differs from Cross-entropy by a constant factor (see the first definition). One important thing to remember is that we usually minimize the log loss instead of the cross-entropy in logistic regression which is not perfectly OK but it is in practice.

• Sorry if this a dum question, but what is $H(p)$? – Charlie Parker Jan 19 '18 at 20:23
• @CharlieParker $H(p)$ is the entropy of $p$. – CKM Jan 22 '18 at 3:35
• @chandresh in logistic regression we have true probabilities {1,0}, so log_loss is equivalent to cross-entropy. Why it is not perfectly OK to optimize log_loss instead of the cross-entropy? – Vadym B. Jun 5 '18 at 10:47
• @VadymB. If you see my the very first and the last eq, you will realize that two losses differ by a constant (here $H(p)$). Hence, it's not perfectly OK. – CKM Jun 5 '18 at 12:42
• Just to clarify...since "perfectly OK" is vague. They have exactly the same minimum, so it is perfectly okay to ignore the constant offset during minimization, it is just not okay if you were to try and compare losses across different datasets (which might have different H(p) values). – slund Nov 11 '18 at 4:56

yes they are related.
the cross entropy used in logistic regression is derived from the Maximum Likelihood principle (or equivalently minimise (- log(likelihood))). see section 28.2.1 Kullback-Liebler divergence:

Suppose ν and µ are the distributions of two probability models, and ν << µ. Then the cross-entropy is the expected negative log-likelihood of the model corresponding to ν, when the actual distribution is µ