Linear Regression Explained
We’ll build the intuition behind linear regression, understand how a model learns its parameters, and see what the training process looks like.
Linear regression is used to find relationship between features and a label. Linear regression model works with numbers so features and label should be numerical values.
Features are inputs or independent variables that are used to predict label (output value)
Suppose we have historical data about the house size and its price in thousand dollars. Given the size of a new house, we want to predict how much it will cost.
This is a regression problem because the output is a continuous numerical value.
Plotting these point would give the following graph:
A model can be created by drawing a best fit line through the points:
Linear regression equation
The model would be mathematiclly:
- y house price — the value we want to predict.
- m is the slope of the line.
- x is house size — input value.
- b is the y-intercept.
In ML terms, the linear regression model would be:
- y is the predicted label — the output.
- b is the bias of the model. Bias is a parameter of the model and is calculated during training.
- w1 is the weight of the feature. Weight is a parameter of the model and is calculated during training.
- x1 is a feature — the input.
weight and bias are learned during training to produce the best model.
Get Hamza Ahmed’s stories in your inbox
Join Medium for free to get updates from this writer.
From the model or line we made, the bias is 65.79 (where the line intersects at y) and the weight is 0.1565 (slope of the line)
The model can be defined from this equation:
This equation can be used to make predictions, we would need the input value (house size) to find the output (house price) according to the model we built.
Models with multiple features
Although the example in this section uses only one feature. In real world, the house price depend on multiple features like no. of floors, area, location, no. of basic amenities, etc. For example, a model that takes five features would be written as follows:
Conclusion
By learning the weights and bias from historical examples, the model can represent the relationship between features and a label as a line or linear equation. While our example used only house size, the same idea can be extended to multiple features, allowing the model to capture more complex real-world relationships.










