DEV Community

Cover image for Day 2 — Linear Regression: How a Straight Line Learns From Data
Chanchal Singh
Chanchal Singh

Posted on

Day 2 — Linear Regression: How a Straight Line Learns From Data

Riya is in school.
Exams are coming.

Her elder sister notices something interesting.

Study Hours Marks
1 hour 20
2 hours 40
3 hours 60

The sister laughs and says:

“Arre, the more you study, the more marks you get — very predictable!”

Without knowing it, Riya’s sister just did Linear Regression.


So… What Is Linear Regression Really?

Forget the big name.

Linear Regression simply means:

Finding a straight-line relationship between input and output.

In normal human language:

  • Input increases
  • Output increases (or decreases)
  • In a steady, predictable way

That steady behavior is the key.


Why a “Straight Line”?

Because life is sometimes simple.

Think about:

  • More work experience → more salary
  • Bigger house → higher price
  • More units used → higher electricity bill

Your brain already expects a straight pattern.

Linear regression just draws that pattern using data.


What Is the Model Actually Doing?

Imagine a board with many dots on it 📍
Each dot is one real example.

Linear regression’s job is:

“Let me draw ONE straight line that passes as close as possible to all these dots.”

Linear Regression graph

Not touching every dot.
Not perfect.
Just the best overall line.

That’s it. That’s the model.


Simple vs Multiple Linear Regression

1. Simple Linear Regression

One input → one output

Example:

  • Hours studied → Marks

2. Multiple Linear Regression

Many inputs → one output

Example:

  • House size
  • Number of rooms
  • Location

→ House price

Same idea.
Just more information.

Simple vs Multiple Linear regression graph


Coefficients — The Real Power

Imagine an HR manager deciding your salary.

She looks at two things:

  • Your experience
  • Your skills

But she doesn’t treat them equally.

Imagine this formula (don’t fear it):

Salary =
(Experience × 5000) + (Skills × 3000) + Base Pay

Those numbers 5000 and 3000 are called coefficients.

She thinks:

  • “Experience adds a lot of value.”
  • “Skills add value too, but a little less.”

Those hidden importance levels are called coefficients.

HR deciding your salary based on various factors

If something changes the salary more, it gets a bigger number.
If it changes the salary less, it gets a smaller number.

Just like cooking:

  • Salt affects taste a lot
  • Chili affects taste, but less

That’s why companies love linear regression.
It doesn’t just predict a number — it explains why that number makes sense.

Bigger coefficient = bigger influence.

Simple.


Intercept — The Starting Point

What if someone has:

  • 0 experience
  • 0 skills

Will salary be zero?

No.

There’s usually a base salary.

That base value is called the intercept.

In simple words:

Intercept is where the line starts.


Why Linear Regression Is Everywhere

Because it is:

  • Easy to understand
  • Fast to train
  • Easy to explain to managers
  • Very popular in interviews

Interview truth:

They don’t care if you remember the formula.
They care if you understand the behavior.


When This Straight Line Becomes a Bad Idea

Now imagine:

  • Salary jumps suddenly
  • Prices go up and down randomly
  • Data looks like curves

Trying to force a straight line there is like:

“Using a ruler to measure a circle.”

It won’t work well.

We’ll break this properly later.


Tiny Brain Exercise 🧠

Think about your monthly mobile bill.

  • More data used → higher bill
  • Less data → lower bill

You already expect a straight relationship.

That expectation is linear regression intuition.


3 Things You Must Remember

  • Linear regression fits a straight line
  • Coefficients show importance
  • Intercept is the starting value

What’s Coming Next 👀

Now that we have a line…

Big question:

How do we know if this line is good or terrible?

That’s where errors and loss functions enter.

👉 Day 3 — Errors & Loss Functions: Measuring How Wrong a Model Is

I love breaking down complex topics into simple, easy-to-understand explanations so everyone can follow along. If you're into learning AI in a beginner-friendly way, make sure to follow for more!

Connect on Linkedin: https://www.linkedin.com/in/chanchalsingh22/
Connect on YouTube: https://www.youtube.com/@Brains_Behind_Bots

Top comments (0)