The mean squared error is probably one of the very first evaluation metrics that you might've used when making machine learning models.

Yet most people don't have a clear intuition about how it works, let's fix that today!

🧵 👇🏻
📍 The mean squared error (MSE) is a common loss function used for 'regression' problems.

Regression models are used for predicting quantitave values based on data like the prices of houses in an area, future height growth of a plant etc.
📈 MSE is calculated as the sum of the squared difference between the predicted and actual values of the target variable.

Let us break this down with the help of an example 👇🏻
A linear regression model is trained on some data of plants to predict their lifespan.

This picture shows one of the data points, the height and its corelation to the lifespan along the predicted lifespan according to our linear regression model.
You can notice how the predicted lifespan does not exactly coincide with the values of the ground truth.

The difference between the predicted value and the actual value is the ‘error’.
These errors can be positive for negative, for example:

• If the predicted lifespan is 10 years and the actual lifespan is 5 years, the error is -5 years

• Similarly, if the predicted lifespan is 5 years and the actual lifespan is 10 years, the error is +5 years.
⚠️ You will notice that adding these up, we get an error of -5 + 5 = 0, which does not make sense, there is an error but its not being reflected.

Which is why we square these errors and then sum them up so that the error is actually being reflected.
In the previous case, squaring them (-5² = 25, 5² = 25) then adding them (25+25) gives us 50.

Thi signifies that there is an error unlike just adding them as is which gives us 0.

This is called the residual error and forms a part of the MSE formula.
We sum up all the residual errors, hence the Summation (Σ) in the formula.

You can read about sigma notation here if you don't know how it works 👇🏻
🔗 mathsisfun.com/algebra/sigma-…
Then we divde this by all the number of data points (1/n) to get the ‘mean’ or average, which gives the MSE.
Let's recap, we're taking the errors (red parts), squaring them and then adding them all up.

Finally we divide all of this with the number of data points giving us the MSE which is how "wrong" our model is.

The lower the MSE, the better the model is.
Theoretically lets say the MSE is 0 then the model is perfect, all the predictions will exactly match with the ground truth.

In this example we’ll be able to predict the lifespan of a plant with a linear regression model 100% correctly.
On the other hand if the MSE is very high, then the model is not very accurate, it will predict the lifespan of a plant with a high degree of error.

With all that being said, this metric isn't perfect, there are some caveats when using the MSE 👇🏻
1️⃣ Avoiding overfitting

We have to be careful when using this metric, as sometimes when the MSE is low, the model may be overfitting, which means that the model is not able to generalize well to new data.
2️⃣ Exaggeration because of outliers

Since we are squaring the errors, we can also get a high MSE if even some of the residual errors are high which can be a problem. In order to avoid this, we can use the Root Mean Squared Error (RMSE), which is the square root of the MSE.
If you liked this thread make sure you retweet it and follow @PrasoonPratham.

I make a lot of content about machine learning and web3 that you don't want to miss out on.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Pratham

Pratham Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @PrasoonPratham

26 Sep
This image sold for $69.3 million as an 'NFT', one of the most fascinating applications of blockchains.

You must've already heard about it but do you know what NFTs really are and how they work?

Here's an explanation in under 5 minutes.
(+ how you can make your own!)
🧵 👇🏻 Image
📖 NFT is short for 'Non-Fungible Tokens'.

When we say something is fungible, that means that it can replaced by something that is exactly the same value.

For example you can you take a 100 dollar bill and another one, they have the same value and are interchangable. Image
💵 There's nothing unique about a specific 100 dollar bill, there are probably millions of them in circulation.

When we say something is non-fungible it means that it is unique and cannot be exchanged for something else.

You cannot exchange the Mona Lisa for something else. Image
Read 18 tweets
25 Sep
Solidity smart contract developers are being paid $145,000/year on AVERAGE right now, and rightfully so.

There is extreme demand for smart contract code and not enough supply, but what even is a smart contract?

The thread will explain everything in less than 5 minutes.

🧵 👇🏻
📜 The term "smart contract" was first used by Nick Szabo, a computer scientist and cryptographer, back in 1997.

Just like contracts in the real world, smart contracts are contracts but in the digital world.

Today, they're used on the blockchain.
🖥️ It's a program just like your Python or JavaScript code that runs on the blockchain.

Let's understand this with an example 👇🏻
Read 17 tweets
23 Sep
Web3 is all the rage right now, it is not hard to find solidity developers that are being paid as much as $160k/year.

I've been waiting to dive into it for a while, so here's a structured online curriculum that I have hacked together.

The best part, it's 100% free.

🧵 👇🏻
First of all, wtf even is web3? 🌐

Web3 is the next stage of evolution of the web that will * most probably * be powered by blockchain at its core.

The modern web that we know today is 'web2' and mostly controlled by large corporations like Google, FB etc.
Web3 changes that, it decentralizes the power from these corporations to users and creators.

Today big companies own our data and profit from it, in the web3 world, nobody owns the data, its public and this is possible because of the blockchain ⛓️
Read 13 tweets
23 Sep
Dictionary methods are one of the most powerful and useful topics that I use almost everyday in Python 🐍

You learn all of them in less than 5 minutes with this thread.

🧵 👇🏻
📌 Copy
📌 Clear
Read 13 tweets
12 Sep
Python list methods are incredibly helpful.

You can learn all of them in less than 5 minutes with this thread 🐍

🧵 👇🏻
📌Append

Add/Append items.
📌Clear

Clear the entire list.
Read 13 tweets
9 Sep
New to Python and looking to step up your skills?🐍

Here are 5 projects to work on and as bonus you can even add these to your resume.
🧵 👇🏻
Before you go onto making these projects, it helps to have some degree of proficiency in the fundamentals of Python itself.

• Basic terminal commands
• Basic arithmetic (+,-,/,*)
• Accepting user input
• For & While loops
• Exception handling
• If-Else statements

...
..
• Functions, modules & Imports
• Object oriented programming:Classes, Objects, Methods
• PIP (Pypi)
• List slicing
• String formatting
• Dictionaries & Tuples
• Managing environments

There are more topics but you can probably learn those as you go, here's the list 👇🏻
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(