MLops : Session - 4
In the last session, I discussed how to train your model using Linear Regression and finding the value of coefficient and bias. Today I just try to clear the things that how fit() function works internally.
Now we see how to make our model more effective and more accurate. For a better understanding, we just go through some visuals(graph)...
This is the graph for the same dataset which we use in the last session. You can see if we try to draw a straight line going through all points, it's quite not possible.
So our machine just tries to find those values of coefficient and bias which represent a more accurate model. Our machine just tries to remove the residual or error, because if the error is less, the accuracy of our model increases.
Like this, they internally choose many values of coefficient and bias and check whether it gets a minimum error.
We have some algorithms by which our machine calculates the minimum error and finds the best fit line(Regression line).
The algorithm behind Linear Regression Model:
Ordinary Least Square method:
The regression algorithm is trying to find the best fitting line, by minimizing the square of the sum of all predicted and actual value ( Sum of Square of Residual = SUM( y - y^)2 ).
Where: y̅, is average line of all data points, y is actual value, y^ is predicted value. SSres is sum of squares of residual and SStot is sum of square of total.
Evaluation Metrics for regression: (all of these are loss function, so we have to minimize them)
- Mean Absolute Error - MAE
- Mean Squared Error - MSE
- Root Mean Square Error - RMSE
Mostly 90% model use MSE because MAE won’t punish large errors, so we use MSE. You can check the formulas for these here https://en.wikipedia.org/wiki/Coefficient_of_determination.
How we know that our model is best or not...?🤔
To find this, we use metrics. If you want to check that prediction is right or not, for this we provide more than half a dataset to train our model and use the remaining dataset for testing. By this, we find the accuracy of our model.
By this, you can match the value of y_pred with y_test and find the accuracy of your model.
We must do this always to check that your model predicts right or not...
Hope we meet again soon.
Happy Learning :)