Tivadar Danka Profile picture
Sep 4, 2025 16 tweets 5 min read Read on X
Logistic regression is one of the simplest models in machine learning, and one of the most revealing.

It shows how to move from geometric intuition to probabilistic reasoning. Mastering it sets the foundation for everything else.

Let’s dissect it step by step! Image
Let’s start with the most basic setup possible: one feature, two classes.

You’re predicting if a student passes or fails based on hours studied.

Your input x is a number, and your output y is either 0 or 1.

Let's build a predictive model! Image
We need a model that outputs values between 0 and 1.

Enter the sigmoid function: σ(ax + b).

If σ(ax + b) > 0.5, we predict pass (1).

Otherwise, fail (0).

It’s a clean way to represent uncertainty with math. Image
So what is logistic regression, really?

It’s just a linear regression plus a sigmoid.

We learn the best a and b from data, then use that to turn any x into a probability. Image
Let’s unpack this model.

First, we apply the linear transformation: y = ax + b.

This is just a line, our old friend from high school algebra.

But it plays a key role in shaping the output. Image
The output of ax + b is called a logit.

Positive logits suggest pass, negative suggest fail.

It's still a number on a line, not yet a probability.

That comes next.
Next, we exponentiate the logit: eᵃˣ⁺ᵇ.

This guarantees the output is always positive.

We’re preparing the value for normalization, and exponentiation bends the scale in our favor. Image
Now we flip it: e⁻⁽ᵃˣ⁺ᵇ⁾.

This inverts the curve and sets us up to approach 1 asymptotically. Image
We add 1, and obtain 1 + e⁻⁽ᵃˣ⁺ᵇ⁾.

This keeps everything above 1. It prevents division by zero in the next step, and squeezes the values of the reciprocals between 0 and 1.

This tiny change stabilizes the entire model. Image
Finally, we take the reciprocal: 1 / (1 + e⁻⁽ᵃˣ⁺ᵇ⁾).

This gives us the full sigmoid function, and maps the entire real line to (0, 1).

Now we have a proper probability. Image
We’ve seen how to turn a number into a probability.

But what about geometry? That becomes clear in higher dimensions.

Let’s level up.
In 2D, the model becomes a plane: y = a₁x₁ + a₂x₂ + b.

The decision boundary is where this equals 0. Points above the plane get one class, below get another.

The model is slicing space into two halves. Image
The logit in higher dimensions measures signed distance to the boundary.

It tells you how confidently the model classifies a point. Closer to 0 means more uncertainty.

It’s probability with geometric roots. Image
Logistic regression is a blueprint for how modern models make decisions.

It blends math, geometry, and probability in one clean package.

Understand it deeply, and you’ll see it everywhere.
Most machine learning practitioners don’t understand the math behind their models.

That's why I've created a FREE roadmap for my 27,000+ newsletter subscribers.

Get the roadmap here: thepalindrome.org/p/the-roadmap-…
The Mathematics of Machine Learning book is now at 10% on Amazon.

I have packed 20 years of math studies into 700 pages full of intuitive and application-oriented lessons, the ultimate learning resource for you.

Get it now: amazon.com/Mathematics-Ma…

• • •

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

Keep Current with Tivadar Danka

Tivadar Danka 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 @TivadarDanka

Jan 20
The single most undervalued fact of linear algebra: matrices are graphs, and graphs are matrices.

Encoding matrices as graphs is a cheat code, making complex behavior simple to study.

Let me show you how! Image
If you looked at the example above, you probably figured out the rule.

Each row is a node, and each element represents a directed and weighted edge. Edges of zero elements are omitted.

The element in the 𝑖-th row and 𝑗-th column corresponds to an edge going from 𝑖 to 𝑗.
To unwrap the definition a bit, let's check the first row, which corresponds to the edges outgoing from the first node. Image
Read 18 tweets
Jan 14
Matrix multiplication is not easy to understand.

Even looking at the definition used to make me sweat, let alone trying to comprehend the pattern. Yet, there is a stunningly simple explanation behind it.

Let's pull back the curtain! Image
First, the raw definition.

This is how the product of A and B is given. Not the easiest (or most pleasant) to look at.

We are going to unwrap this. Image
Here is a quick visualization before the technical details.

The element in the i-th row and j-th column of AB is the dot product of A's i-th row and B's j-th column. Image
Read 17 tweets
Jan 8
Behold one of the mightiest tools in mathematics: the camel principle.

I am dead serious. Deep down, this tiny rule is the cog in many methods. Ones that you use every day.

Here is what it is, how it works, and why it is essential: Image
First, the story:

The old Arab passes away, leaving half of his fortune to his eldest son, third to his middle son, and ninth to his smallest.

Upon opening the stable, they realize that the old man had 17 camels. Image
This is a problem, as they cannot split 17 camels into 1/2, 1/3, and 1/9 without cutting some in half.

So, they turn to the wise neighbor for advice. Image
Read 18 tweets
Jan 1
The single most undervalued fact of linear algebra: matrices are graphs, and graphs are matrices.

Encoding matrices as graphs is a cheat code, making complex behavior simple to study.

Let me show you how! Image
If you looked at the example above, you probably figured out the rule.

Each row is a node, and each element represents a directed and weighted edge. Edges of zero elements are omitted.

The element in the 𝑖-th row and 𝑗-th column corresponds to an edge going from 𝑖 to 𝑗.
To unwrap the definition a bit, let's check the first row, which corresponds to the edges outgoing from the first node. Image
Read 18 tweets
Dec 11, 2025
The single most undervalued fact of linear algebra: matrices are graphs, and graphs are matrices.

Encoding matrices as graphs is a cheat code, making complex behavior simple to study.

Let me show you how! Image
If you looked at the example above, you probably figured out the rule.

Each row is a node, and each element represents a directed and weighted edge. Edges of zero elements are omitted.

The element in the 𝑖-th row and 𝑗-th column corresponds to an edge going from 𝑖 to 𝑗.
To unwrap the definition a bit, let's check the first row, which corresponds to the edges outgoing from the first node. Image
Read 18 tweets
Dec 9, 2025
Matrix multiplication is not easy to understand.

Even looking at the definition used to make me sweat, let alone trying to comprehend the pattern. Yet, there is a stunningly simple explanation behind it.

Let's pull back the curtain! Image
First, the raw definition.

This is how the product of A and B is given. Not the easiest (or most pleasant) to look at.

We are going to unwrap this. Image
Here is a quick visualization before the technical details.

The element in the i-th row and j-th column of AB is the dot product of A's i-th row and B's j-th column. Image
Read 17 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!

:(