Logistic Regression clearly explained πŸ‘‡πŸ»

@iamjosepferrer
Josep Ferrer@iamjosepferrer
23 views Feb 12, 2025 ~2 min read
Advertisement
1
Logistic Regression clearly explained πŸ‘‡πŸ»
Media image
2
1️⃣ π—Ÿπ—’π—šπ—œπ—¦π—§π—œπ—– π—₯π—˜π—šπ—₯π—˜π—¦π—¦π—œπ—’π—‘
It is a binary classification model used to classify our input data into two main categories.

It can be extended to multiple classifications... but today we'll focus on a binary one.

Also known as Simple Logistic Regression.
Media image
3
2️⃣ 𝗛𝗒π—ͺ 𝗧𝗒 π—–π—’π— π—£π—¨π—§π—˜ π—œπ—§?
The Sigmoid Function is our mathematical wand, turning numbers into neat probabilities between 0 and 1.

It's what makes Logistic Regression tick, giving us a clear 'probabilistic' picture.
Media image
4
3️⃣ 𝗛𝗒π—ͺ 𝗧𝗒 π——π—˜π—™π—œπ—‘π—˜ π—§π—›π—˜ π—•π—˜π—¦π—§ π—™π—œπ—§?
For every parametric ML algorithm, we need a LOSS FUNCTION.

It is our map to find our optimal solution or global minimum.

(hoping there is one! πŸ˜‰)
Media image
5
✚ 𝗕𝗒𝗑𝗨𝗦 - FROM LINEAR TO LOGISTIC REGRESSION
To obtain the sigmoid function, we can derive it from the Linear Regression equation.
Media image
6
4️⃣ 𝗛𝗒π—ͺ 𝗧𝗒 π—’π—•π—§π—”π—œπ—‘ π—œπ—§ π— π—”π—§π—›π—˜π— π—”π—§π—œπ—–π—”π—Ÿπ—Ÿπ—¬?
For a binary classification, the model output corresponds to a predicted y:
- 0 for one class
- 1 for the other one.

(Remember we are in a BINARY classification model... at least for now!)
Media image
7
π—›π—¬π—£π—’π—§π—›π—˜π—¦π—œπ—¦
Assuming a hypothesis y_hat as the probability of y being 1, we get two main equations.

As a starting point, we mathematically obtain the corresponding LOSS FUNCTION from those equations.

We end up with the Binary Cross-Entropy or Log Loss Function.
Media image
8
5️⃣ π—™π—œπ—‘π—— π—§π—›π—˜ π—’π—£π—§π—œπ— π—”π—Ÿ π—¦π—’π—Ÿπ—¨π—§π—œπ—’π—‘
To find our optimal parameter values, we use the gradient descent.

It carefully navigates the cost function landscape, seeking the valley of optimal parameters.

And iteratively we get closer to the optimal solution.
Media image
9
6️⃣ π— π—’π——π—˜π—Ÿ π—˜π—©π—”π—Ÿπ—¨π—”π—§π—œπ—’π—‘
Once our model's journey is complete, we assess its valor through trials like the Confusion Matrix and ROC Curve.

Only the models that prove their worth will be knighted for deployment.
Media image
10
7️⃣ π—”π—¦π—¦π—¨π— π—£π—§π—œπ—’π—‘π—¦ 𝗒𝗙 π—§π—›π—˜ π— π—’π——π—˜π—Ÿ
Our Logistic Regression model is built on foundations firm in assumptions:

1. Binary outcomes.
2. Linearity in Log Odds.
3. No Multicollinearity
4. Large Sample Size
Media image
11
Mastering Logistic Regression is a craft, a blend of art and science.

And this is all for now!
12
If you are interested in...
β€’ Python 🐍
β€’ SQL πŸ’Ύ
β€’ ML/MLOps πŸ› 
β€’ LLMs & NLP πŸ—£
β€’ DataViz πŸ—£
β€’ AI Engineering βš™οΈ

Then follow me β†’ @rfeers
13
Did you like this thread?

Then join my DataBites newsletter to get all my content right to your mail every Sunday! 🧩

πŸ‘‰πŸ» databites.tech πŸ€“
Media image
Actions
What You Can Do
  • Export as PDF or Markdown
  • Batch Export to Notion
  • Bookmark & Highlight
  • Screenshot Tweet
Create Free Account

Includes 7-day Premium trial

Advertisement