Lesson 6: Mathematical Explanation
As with most ML algorithms, libraries and functions are ready for you to use directly, without even knowing the underlying math formulas and equations.
That's why I left this part to the end of this example, as a "bonus section".
Of course, senior ML engineers would argue, but this is my personal philosophy I used while teaching many programming languages and frameworks:
- Quick practical results first, to get the motivation and momentum
- And then deeper understanding, part by part
So now, as you've seen Linear Regression in action, let's see what's under the hood.
Generally, simple Linear Regression with one column feature can be described with this equation:
1Y = a + b * X
The variable b
is called a coefficient or slope, and the variable a
is called intercept.
And the goal of the model that we train is to calculate the best possible values for a
and b
after being trained on the values of X
and Y
.
Then, whenever we run .predict(X)
, the model uses that formula with all the known number values and calculates the Y
.
In some tutorials, you may find different letters or their order representing this equation, like y = mx + c
, but mathematically, it's the same thing.
Multiple linear regression and polynomial regression have a bit more complex formulas, and we will discuss them in the next lesson.
For now, we have finished the example project of a simple linear regression. As homework, you may experiment and try what results you would get with things like:
- Different CSV files with more data
- Different train/test split than 80-20%
- Different
random_state
value
- Intro
- Example 1: More Simple
- Example 2: More Complex
No comments or questions yet...