# Why not use the MSE instead of the current logistic regression?

When watching the machine learning course on Coursera by Andrew Ng, in the logistic regression week, the cost function was a bit more complex than the one for linear regression, but definitely not that hard.

But it got me thinking, why not use the same cost function for logistic regression?

So, the cost function would be $$\frac{1}{2m} \sum_{i}^m|h(x_i) - y_i|^2$$, where $$h(x_i)$$ is our hypothesis $$\text{function}(\text{sigmoid}(X * \theta))$$, $$m$$ is the number of training examples and $$x_i$$ and $$y_i$$ are our $$ith$$ training example?

The mean squared error (MSE), $$J(\theta) = \frac{1}{2m}\sum_{i=1}^m(h_\theta(x_i)-y_i)^2$$, is not as appropriate as a cost function for classification, given that the MSE makes assumptions about the data that are not appropriate for classification. Though, as an optimization objective, it is still possible to attempt to minimize MSE even in a classification problem, and thus still learn parameters $$\theta$$.

The new cost function has better convergence characteristics as it is more inline with the objective.

See link for the precise mathematical formulation that explains these loss functions from a probabilistic perspective.

Note that the absolute value is redundant because $$\forall x:x^2\geq0$$.

I hope this clarifies the matter.

• MLE is also not guaranteed to be convex though. It's I guess 'relatively' more convex. – DuttaA Sep 5 '19 at 3:39
• @DuttaA OOF! you're right. Thanks for this comment! I did some reading on this and updated with a link that seems to provide the rigorous reasons. – respectful Sep 5 '19 at 5:13

I mean you technically could (it's not going to break or something) however, cross entropy is much better suited for classification as it penalizes for misclassification errors: have a look at the function: when you are wrong the loss goes to infinity: you are either from one class or another. MSE is designed for regression where you have nuance: you get close to target is sometimes good enough. You should try both and you will see the performance will be much better for the cross entropy.

• MSE also penalizes misclassification error, you could say it doesn't penalize it as much as MLE error function which might lead to the NN focusing on minimizing loss rather than increasing accuracy. – DuttaA Sep 5 '19 at 11:30
• I would not call it penalising misclassification per se, as it would be predicting probabilities but implicitely yes you're right I should have mentionned that – RonsenbergVI Sep 5 '19 at 11:45
• It doesn't predict probablities though. The target is either 1 or 0. Since its output is between 0-1 or we design it to be so (like in softmax) and also because I think conventional literature somewhat treats it in the same way, so we interpret it as a probablity. Case in point is SVMs which try to just escape from a region, but if we normalize it tgen it's just probability. While in SVM we will try to reach infinity hear reaching the same will result in a 1 and thus 0. But then again I think the viewpoint varies from person to person.(NOTE: you can always edit your answer to add more details) – DuttaA Sep 5 '19 at 14:08