Linear Regression
What Is Linear Regression?
Why the Name “Linear Regression”?
The term linear refers to a straight line. In this algorithm, the data features are linearly related — meaning, as one feature changes, the other changes in a consistent way (not always exact, but with a similar trend).
The word regression has its roots in statistics and history. The concept was first introduced by Sir Francis Galton in the late 1800s while studying the relationship between parents' heights and their children's heights.
He observed that tall parents tended to have tall children, but the children weren’t as tall — and short parents had shorter children, but not as short. He called this effect "regression to the mean", meaning extreme traits tend to move toward the average over generations.
Later, Karl Pearson built on Galton’s work and gave us the mathematical framework we now call linear regression — a method to find a best-fit straight line through data, helping us make predictions.
What Does It Do?
This best-fit line—can then be used to predict the weight of a new person just by knowing their height.
Mathematical Intuition
Where:
-
x is the input (or feature or called the independent variable),
-
y is the output (or target, or called the dependent variable, which we wanted to predict),
-
m is the slope (rate of change : how much y changes with x),
-
c is the bias or intercept (where the line crosses the y-axis).
Yes — just some initial random values.
Then comes the learning part. where it learns and optimizes the values of m and c.
How Does It Learn?
With each data point we feed in, we calculate how far our predicted y is from the actual y (this difference is called the error or loss).
We combine these errors into a single number and aim to reduce it. There are different methods to combine the error. like the ordinary least square method(OLS)
where the combined error is called RSS(Residual sum of square), and r1,r2,..etc are the individual error of each data point.
This combined error is the one we wanted to minimize to estimate m and c. we adjust our guesses of m and c — just a little — in the right direction, so that the error becomes smaller next time.
This process is repeated across all data points, often for multiple passes over the same dataset.
Eventually, m and c settle into values that minimize the overall error, and we get our best-fit line.
Using some calculus while reducing RSS we can find out the value of m and c.
Real-Life Example
Predicting House Prices
Let's say, we want to estimate the price of a house based on its size (in square feet). We collect data on houses recently sold in the area — their sizes and prices — and use that data to find a relationship.
20,000 + (120 × 1000) = 140,000
Where Is It Used ?
Linear regression is used in many fields where understanding trends or making predictions is important:
-
Business: Forecasting sales based on advertising spend
-
Healthcare: Predicting patient recovery time based on age and treatment duration
-
Economics: Estimating consumer spending based on income
-
Agriculture: Predicting crop yield based on rainfall and fertilizer usage
-
Education: Predicting student performance based on study hours
When to Use It ?
Use linear regression when:
-
We want to predict a numeric value (e.g., salary, temperature, price).
-
We suspect a linear relationship (straight-line pattern) between variables.
-
We have continuous input (independent) and output (dependent) variables.
-
We need a simple, interpretable model to understand how inputs affect output.
Limitations
Linear regression is powerful but has some limitations:
If the actual relationship is curved or complex (non-linear), linear regression will miss patterns and unable to capture what's really going on(underfitting) and thereby give poor predictions.
Conclusion
Linear regression is simple, intuitive, useful when the pattern is right. It works best when you sense a straight-line relationship and want something that’s easy to understand and quick to apply. But like any tool, it has its limits. The real skill lies in knowing when it fits — and when it doesn’t.
Comments
Post a Comment