Main Idea of Least Squares Method and Linear Regression

1 5 47
calendar_todayschedule1 min read
— Originally published at dev.to

Hello, I'm Ganesh. I'm building git-lrc, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. Star git-lrc on GitHub to help more developers discover the project. Do give it a try and share your feedback for improving the product.

Linear Regression is a method that finds the best fitting line for a set of data points.

It is used to predict the value of a dependent variable based on the value of one or more independent variables.

let's assume we have a set of data points $(x_1, y_1), (x_2, y_2), ..., (x_n, y_n)$.

The data points can be represented as a scatter plot.

The data points are scattered in a way that it may represent a line.

where each point $(x_i, y_i)$ represents a data point.

A line can be represented as $y = mx + b$, where $m$ is the slope and $b$ is the y-intercept.

Usually, we have some random value of $m$ and $b$ and we want to find the best value of $m$ and $b$ such that the line passes through the data points.

For example in this graph there are mulitple data points, and we want to find the best fitting line for these data points.

This can be done using the least squares method.

Least Squares Method

The least squares method is a method that finds the best fitting line for a set of data points.

we calculate the sum of the squares of the differences between the actual values and the predicted values.

$(y_i - (mx_i + b))^2$

We want to minimize this value.

So, we check each state of line and calculate the sum of the squares of the differences between the actual values and the predicted values.

We choose the line that minimizes this value.

How this is done mathematically

This whole caculation can be done mathematically. I will discuss in depth in my next article.

git-lrc

Any feedback or contributors are welcome! It’s online, source-available, and ready for anyone to use.

Star git-lrc on GitHub

2 Comments

1 vote
1
🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

Your Game’s GC Spikes? Blame Yourself.

PrabashanaDev - Jul 15

Europe Just Dropped the Hammer on AI: A Wake-Up Call?

PrabashanaDev - Jul 15

Mathematical Intuition of Linear Regression

Ganesh Kumar - Jul 6

Internal Architecture of Neural Networks

Ganesh Kumar - May 30

TypeScript Complexity Has Finally Reached the Point of Total Absurdity

Karol Modelskiverified - Apr 23
chevron_left
1.3k Points53 Badges
60Posts
7Comments
4Connections
Right now I'm focused on LiveReview, AI code review that gives teams control over AI-generated code without slowing them down.

Related Jobs

Commenters (This Week)

1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!