Tivadar Danka Profile picture
Sep 4 15 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-…

• • •

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

Sep 3
The way you think about the exponential function is wrong.

Don't think so? I'll convince you. Did you realize that multiplying e by itself π times doesn't make sense?

Here is what's really behind the most important function of all time: Image
First things first: terminologies.

The expression aᵇ is read "a raised to the power of b."

(Or a to the b in short.) Image
The number a is called the base, and b is called the exponent.

Let's start with the basics: positive integer exponents. By definition, aⁿ is the repeated multiplication of a by itself n times.

Sounds simple enough. Image
Read 19 tweets
Sep 1
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 19 tweets
Aug 23
In calculus, going from a single variable to millions of variables is hard.

Understanding the three main types of functions helps make sense of multivariable calculus.

Surprisingly, they share a deep connection. Let's see why: Image
In general, a function assigns elements of one set to another.

This is too abstract for most engineering applications. Let's zoom in a little! Image
As our measurements are often real numbers, we prefer functions that operate on real vectors or scalars.

There are three categories:

1. vector-scalar,
2. vector-vector,
3. and scalar-vector. Image
Read 16 tweets
Aug 22
The most important concept in probability and statistics: the expected value

For instance, all the popular loss functions in machine learning, like cross-entropy, are expected values. However, its definition is far from intuitive.

Here is what's behind the scenes: Image
It's better to start with an example.

So, let's play a simple game! The rules: I’ll toss a coin, and if it comes up heads, you win $1. However, if it is tails, you lose $2.

Should you even play this game with me? We’ll find out.
After n rounds, your earnings can be calculated by the number of heads times $1 minus the number of tails times $2.

If we divide total earnings by n, we obtain your average earnings per round. Image
Read 16 tweets
Aug 21
Adding numbers is more exciting than you think.

For instance, summing the same alternating sequence of 1s and (-1)s can either be zero or one, depending on how we group the terms. What's wrong?

I'll explain. Enter the beautiful world of infinite series: Image
Let’s go back to square one: the sum of infinitely many terms is called an infinite series. (Or series in short.)

Infinite series form the foundations of mathematics. Image
Do infinite series make sense? Sure.

Take a look at the geometric series: summing the positive powers of 1/2 adds up to one.

Here is a visual proof to convince you. Image
Read 24 tweets
Aug 20
The main reason math is considered difficult: proofs.

Reading and writing proofs are hard, but you cannot get away without them. The best way to learn is to do.

So, let's deconstruct the proof of the most famous mathematical result: the Pythagorean theorem. Image
Here it is in its full glory.

Theorem. (The Pythagorean theorem.) Let ABC be a right triangle, let a and b be the lengths of its two legs, and let c be the length of its hypotenuse.

Then a² + b² = c². Image
Now, the proof. Mathematical proofs often feel like pulling a rabbit out of a hat. I’ll go a bit overboard and start by pulling out two rabbits.

The first rabbit. Take a look at the following picture.

The depicted square’s side is a + b long, so its area is (a + b)². Image
Read 18 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!

:(