DEV Community

Muhammad Sahim Bhaur
Muhammad Sahim Bhaur

Posted on

Square Mean Error vs. Log Loss

Overview of cost functions

These two functions are used to calculate the loss and then the cost of our models.

Loss being the difference between our predictions and ground labels for an instance while cost being the average sum of differences from our predictions.

The following are the few over arching differences

Comparison of Square Mean Error (SME) and Log Loss functions.

Formula's of each function

Square Mean Error

loss=12(y^y)2loss = \frac{1}{2}(\hat{y}-y)^2

Log Loss

loss=((y)logy^+(1y)log(1y^)) loss = - ( (y)\log{\hat{y}} + (1-y)\log{(1-\hat{y})} )

Let's see the two functions in action:

y y_hat LOG LOSS SME
0.1 0.9 2.08 0.64
0.2 0.8 1.33 0.36
0.3 0.7 0.95 0.16
0.4 0.6 0.75 0.04
0.5 0.5 0.69 0.0
0.6 0.4 0.75 0.04
0.7 0.3 0.95 0.16
0.8 0.2 1.33 0.36
0.9 0.1 2.08 0.64

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay