Josep Ferrer Profile picture
Apr 28, 2024 โ€ข 13 tweets โ€ข 5 min read โ€ข Read on X
Struggling with Machine Learning algorithms? ๐Ÿค–

Then you better stay with me! ๐Ÿค“

We are going back to the basics to simplify ML algorithms.
... today's turn is Multiple Linear Regression! ๐Ÿ‘‡๐Ÿป Image
In MLR, imagine you're baking.

You've got different ingredients or variables.

You need the perfect recipe (model) for your cake (prediction).

Each ingredient's quantity (coefficient) affects the taste (outcome).
1๏ธโƒฃ ๐——๐—”๐—ง๐—” ๐—š๐—”๐—ง๐—›๐—˜๐—ฅ๐—œ๐—ก๐—š ๐—ฃ๐—›๐—”๐—ฆ๐—˜
We're using height and weight - a classic duo often assumed to have a linear relationship.

But assumptions in data science? No way! ๐Ÿง

Let's find out:
- Do height and weight really share a linear bond? Image
2๏ธโƒฃ ๐——๐—”๐—ง๐—” ๐—˜๐—ซ๐—ฃ๐—Ÿ๐—ข๐—ฅ๐—”๐—ง๐—œ๐—ข๐—ก ๐—ง๐—œ๐— ๐—˜! ๐Ÿ•ต๏ธโ€โ™‚๏ธ
Before we get our hands dirty with modeling, let's take a closer look at our data.

Remember, the essence of a great model lies in truly understanding your data first. ๐Ÿ—๏ธ

However... what about Gender? Image
๐—š๐—˜๐—ก๐——๐—˜๐—ฅ'๐—ฆ ๐—ฅ๐—ข๐—Ÿ๐—˜
Let's start with the basics: when we plot height against weight, we see a linear pattern emerge.

However... when we consider gender...

It turns out that it significantly affects the weight for a given height. Image
3๏ธโƒฃ ๐—•๐—˜๐—ฌ๐—ข๐—ก๐—— ๐—›๐—˜๐—œ๐—š๐—›๐—ง
Splitting our data by gender, we can perform two SINGLE linear regression.

The slopes of these lines are almost identical, which indicates a similar behavior.

But what about the intercepts?

They tell us that start from different baselines. ๐Ÿšฆ Image
4๏ธโƒฃ ๐— ๐—จ๐—Ÿ๐—ง๐—œ-๐—ฉ๐—”๐—ฅ๐—œ๐—”๐—•๐—Ÿ๐—˜ ๐Ÿ“
We can add multiple variables to perform a MULTIPLE Linear Regression.

The core theory is the same: We still use a linear function to predict our target.

But we can track N independent values

So we can consider both Height and Gender โžก๏ธ N=2 Image
5๏ธโƒฃ ๐—ง๐—ฌ๐—ฃ๐—˜๐—ฆ ๐—ข๐—™ ๐—ฉ๐—”๐—ฅ๐—œ๐—”๐—•๐—Ÿ๐—˜๐—ฆ ๐ŸŽฒ
MLR accepts both numbers and categories.

HEIGHT is a numerical variable - which is a variable that can be measured.

GENDER is a category - It splits our data into different groups. Image
To consider categories in our model, they have to be encoded into a binary variable.

So say hello to dummy variables! ๐Ÿ‘‹๐Ÿป

We can easily convert our gender variable into a boolean one with 1 and 0. Image
6๏ธโƒฃ ๐—ง๐—›๐—˜ ๐—˜๐—ค๐—จ๐—”๐—ง๐—œ๐—ข๐—ก ๐Ÿงฎ
Our regression equation is like a secret recipe.
It tells us how much of each ingredient (variables) we need.

Any unit increase in height makes the weight increase.

But gender affects this relationship too.

So we need to compute the weights! Image
7๏ธโƒฃ ๐—™๐—œ๐—ก๐—”๐—Ÿ ๐—ฅ๐—˜๐—ฆ๐—จ๐—Ÿ๐—ง๐—ฆ ๐Ÿ
We can use scikit-learn to implement such MLR.

The code is quite straightforward and we can easily obtain all three weights.

We get a single equation for both cases. Image
When considering that gender is either 0 or 1, we obtain two equations.

And they are quite similar to the ones we obtained in the beginning.

So this is all for now on Linear Regression.

Next week I'll write about Logistic Regression!

So you better stay tuned! ๐Ÿค“
Did you like this thread?

Then join my freshly started DataBites newsletter to get all my content right to your mail every Sunday! ๐Ÿงฉ

๐Ÿ‘‰๐Ÿป open.techwriters.info/rfeers
Image

โ€ข โ€ข โ€ข

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

Keep Current with Josep Ferrer

Josep Ferrer 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 @rfeers

Sep 15, 2025
How to make your LLMs smarter and more efficient explained!๐Ÿ‘‡๐Ÿป

(Don't forget to bookmark for later ๐Ÿ˜‰) Image
Creating an LLM demo is a breeze.
But... refining it for production? That's where the real challenge begins! ๐Ÿ› ๏ธ

Teams often grapple with LLMs lacking deep knowledge or delivering inaccurate outputs.

How do we fix this?
Optimization isn't a one-size-fits-all. Approach it along two axes:

๐Ÿง  ๐—–๐—ผ๐—ป๐˜๐—ฒ๐˜…๐˜ ๐—ข๐—ฝ๐˜๐—ถ๐—บ๐—ถ๐˜‡๐—ฎ๐˜๐—ถ๐—ผ๐—ป: Is the model missing the right info?
โš™๏ธ ๐—Ÿ๐—Ÿ๐—  ๐—ข๐—ฝ๐˜๐—ถ๐—บ๐—ถ๐˜‡๐—ฎ๐˜๐—ถ๐—ผ๐—ป: Is the model's output off-target? ๐ŸŽฏ

Let's break down the three primary tools ๐Ÿ’ฅ
Read 10 tweets
Apr 19, 2025
Multiple-class Logistic Regression clearly explained ๐Ÿ‘‡๐Ÿป

(Don't forget to bookmark for later! ๐Ÿ˜‰) Image
By default, Logistic Regression is like a coin toss - heads or tails, A or B.

But what if you have multiple classes?

That's where we adapt our model for MULTIPLE CHOICES!
There are two main ways:
1๏ธโƒฃ ๐—ข๐—ก๐—˜-๐—ฉ๐—ฆ-๐—ฅ๐—˜๐—ฆ๐—ง (๐—ข๐˜ƒ๐—ฅ):
The Logistic Regression model excels in classifying binary choices.

So... what if we train multiple Logistic Regression classifiers for every class?

๐Ÿ’ก The idea would be to focus on classifying a single class vs the rest. Image
Read 13 tweets
Apr 15, 2025
Simple Linear Regression exemplified for dummies๐Ÿ‘‡๐Ÿป

(Don't forget to bookmark for later! ๐Ÿ˜‰) Image
1๏ธโƒฃ ๐——๐—”๐—ง๐—” ๐—š๐—”๐—ง๐—›๐—˜๐—ฅ๐—œ๐—ก๐—š ๐—ฃ๐—›๐—”๐—ฆ๐—˜
We're using height and weight - a classic duo often assumed to have a linear relationship.

But assumptions in data science? No way! ๐Ÿง

Let's find out:
- Do height and weight really share a linear bond? Image
Do you like this post?

Then join my DataBites newsletter to get all my content right to your mail every Sunday! ๐Ÿงฉ

๐Ÿ‘‰๐Ÿป ๐Ÿค“databites.tech
Read 18 tweets
Apr 14, 2025
Linear Regression clearly explained ๐Ÿ‘‡๐Ÿป Image
Linear regression is the simplest statistical regression method used for predictive analysis.

It can be performed with multiple variables.... but today we'll focus on a single one.

Also known as Simple Linear Regression.
1๏ธโƒฃ ๐—ฆ๐—œ๐— ๐—ฃ๐—Ÿ๐—˜ ๐—Ÿ๐—œ๐—ก๐—˜๐—”๐—ฅ ๐—ฅ๐—˜๐—š๐—ฅ๐—˜๐—ฆ๐—ฆ๐—œ๐—ข๐—ก
In Simple Linear Regression, we use one independent variable to predict a dependent one.

The main goal? ๐ŸŽฏ
Finding a line of best fit.

It's simple yet powerful, revealing hidden trends in data. Image
Read 13 tweets
Mar 15, 2025
Linear Regression clearly explained ๐Ÿ‘‡๐Ÿป Image
Linear regression is the simplest statistical regression method used for predictive analysis.

It can be performed with multiple variables.... but today we'll focus on a single one.

Also known as Simple Linear Regression.
1๏ธโƒฃ ๐—ฆ๐—œ๐— ๐—ฃ๐—Ÿ๐—˜ ๐—Ÿ๐—œ๐—ก๐—˜๐—”๐—ฅ ๐—ฅ๐—˜๐—š๐—ฅ๐—˜๐—ฆ๐—ฆ๐—œ๐—ข๐—ก
In Simple Linear Regression, we use one independent variable to predict a dependent one.

The main goal? ๐ŸŽฏ
Finding a line of best fit.

It's simple yet powerful, revealing hidden trends in data. Image
Read 13 tweets
Mar 13, 2025
The Transformer's encoder clearly explained ๐Ÿ‘‡๐Ÿป Image
1๏ธโƒฃ ๐—ช๐—›๐—”๐—ง'๐—ฆ ๐—ง๐—›๐—˜ ๐—˜๐—ก๐—–๐—ข๐——๐—˜๐—ฅ? ๐Ÿง 

The Encoder is the part responsible for processing input tokens through self-attention and feed-forward layers to generate context-aware representations.

๐Ÿ‘‰ Itโ€™s the powerhouse behind understanding sequences in NLP models. Image
Are you enjoying this post?

Then join my newsletter DataBites to get all my content right to your mail every week! ๐Ÿงฉ

๐Ÿ‘‰๐Ÿป databites.tech
Read 16 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

Don't want to be a Premium member but still want to support us?

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

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(