Linear Regression is a statistical or mathematical approach for solving linear equations. A Linear Regression model finds the coefficient and intercepts from given input datas and predict output for any randomly given input.
Linear Regression is the simpliest Machine Learning algorithm.
- When our dependent and independent variables are continious.
- There needs to be a linear relationship between two variables.
- There should be no significant outliner values in the data set.
- House price prediction
- Blood pressure prediction
- Car price prediction
- Advertising cost prediction
- Height prediction
When our output variable is dependent on only one variable then it is called simple linear regression. In the given data set y is only dependent on x, so it is a simple regression.
when our output variable is dependent on two or more independent variables then it is called multiple linear regresssion. In the given data set output z is dependent on x and y.
Let us consider, this is a dataset.
Now the relation between X and y is
Main motive of our model is to find the Intercept(m) and the coefficient(c).
If we know the values of c and m, we can predict the output for any random inputs. One of the best way to find the coefficient and intercept is Least Square Method.
The main equation of Least Square method is:
Here x̅ is the mean of all the values of X and ȳ is the mean of all the values in the Y. This is the Least Squares method.
Our calculation looks like:-
now,
and,
so our m=2.0 and c=2.0 which exactly matches with our data set(As m and c for every row is same).
Our Linear Regression Model is ready. Now we can predict output with any random input.
For the value of x=15, our y will be y=mX + c = 2.0*15 + 2.0 = 32.0
Note: -
- The value of intercept and coefficeint is same for every row in out data set. Thats why the value of m and c is exactly same.
- The score of our model is 1.0 and efficiency is 100%.
- As our score is 1 so there is no error.