Classification problems often use CE instead of MSE
"TLDR: This article analyzes the reasons why MSE is commonly used instead of CE for classification tasks in machine learning, and discusses it in detail from the perspective of distribution and optimization. The article points out that MSE assumes that data obeys Gaussian distribution, but in reality long-tailed distributions are also common, and using MSE directly may lead to poor results. At the same time, the article also mentioned that from an optimization perspective, if the classification problem uses MSE as the loss function, it is a non-convex optimization and it is difficult to find the optimal solution."
Machine learning is usually divided into two categories: regression and classification. The former commonly uses mean square error (MSE), and the latter commonly uses cross entropy (CE). The predecessors must have their reasons for doing this. Let’s analyze it from several angles.
Distribution angle
MSE as a loss function actually has an a priori assumption: the error obeys the standard Gaussian distribution. Here is a simple derivation of the origin of the MSE loss function:
It is nothing more than three steps: assuming distribution, maximum likelihood estimation, and deriving the loss function.
Assume that the error between the predicted value and the actual value obeys the standard Gaussian distribution, that is, , and because , so
The probability density function of is .
Then use the maximum likelihood estimation method:
At this time, the MSE loss function was derived
A little review here
- If it is a Lasso loss function, it is equivalent to the maximum posterior estimate of the parameters obeying the Laplace distribution;
- If it is the loss function of ridge regression, it is equivalent to the maximum posterior estimate of the parameters obeying Gaussian distribution;
And CE assumes that the data obeys Bernoulli distribution/polynomial distribution
The Bernoulli distribution means doing N trials. The probability of success for each trial is and the probability of failure is . Then the expectation of the number of successes is , the variance is , and the probability density function is
Then in the two classification task, given the data set , then for each sample , the probability density function is . We still use the likelihood estimation, which means we can get .
At this time, we will derive the situation except the CE loss function in the second classification.
Therefore, from a priori point of view, in classification tasks, it is more realistic to assume that the data obeys the Bernoulli distribution. Therefore, CE is often used in classification tasks, while MSE is often used in regression tasks.
Let’s discuss it again.
mseassumes that the data distribution is Gaussian distribution. However, in reality, long-tail distribution is also very common, and the effect is not good if MSE is used directly. Therefore, sometimes when doing data EDA, it is found that the data does not conform to the Gaussian distribution and needs to be corrected, such as using logarithmic transformation or boxcox transformation.
Optimization angle
From an optimization perspective, if the classification problem uses MSE as the loss function, it is a non-convex optimization and it is difficult to find the optimal solution.
This is a non-convex function.