Challenges
Linear regression: finding m and b
Artificial Intelligence
Medium
Linear regression
Solves: 7
Linear regression: finding m and b
Author: CyberSamSU
Points
35
Linear regression is the simplest machine learning model that finds the line of best fit through data points: y = m*x + b, where m is the slope, and b is the intercept.
In the general case (ordinary least squares — OLS), m and b are found using the following formulas:
m = (n*sum(x*y) - sum(x)*sum(y)) / (n*sum(x^2) - sum(x)^2)
b = (sum(y) - m*sum(x)) / n
The following 5 points lie on a single straight line (error-free measurement):
| x | y |
|---|---|
-5 | 36 |
1 | 0 |
2 | -6 |
3 | -12 |
5 | -24 |
Find the m and b coefficients of this line.
Write the answer in the format m,b, with a comma, without spaces (for example 3,-2).
To submit a flag, log in.