Definition
DEF
Linear regression is a supervised regression algorithm that models the relationship between input features and a continuous output as a straight line (or hyperplane), by finding the weights that best fit the data.
Diagram
Calculation
Sample dataset
| Age (x) | Weight (y) |
|---|---|
| 24 | 62 |
| 25 | 63 |
| 21 | 72 |
| 27 | 62 |
- ‘x’ is the independent variable or input & ‘y’ is the dependent variable or the output or target
- ‘y’ is a linear function of ‘x’ (since ‘y’ depends on ‘x’)
Equation
Formula for best fit line in linear regression:
where,
- = Intercept (i.e. when , , aka the point where you are meeting the y axis)
- = Slope or Coefficient (i.e. with 1 unit measurement in x-axis, what is the unit measurement in y-axis)
Aim
Main aim of a linear regression is to find out the best fit line, in such a way that the distance between the data points and the predicted points should the very less.
Hypothesis i.e. predicted weight = intercept + slope × datapoint(Age)
Now, this formula is for just one point, but if we want to find out the entire line, we need to keep on changing and . To find the new and , we have to use the Cost Function.