Saturday, May 16, 2020

Simple Linear Regression Implementation (5/5)

In the last article, we saw how to implement simple linear regression from scratch,but that was a long process, right? We can do the same calculation using scikit-learn in just few lines. Exciting!!!

Well what are we waiting for? Let’s dig in!!

(1) Import the required libraries :

(2) Read the data file :

(3) Select useful features from data :

(4) Plot out data on scatter plot :

(5) Divide data into training and testing data :

6) Use scikit-learn to find Intercept and Slope :

(7) Plot the regression line :

(8) Predict the value of co2-emission :

Here you can see that we get the exact same value as our previous article!

(9) Check model accuracy :

In conclusion, we can say that the line of code required to find the regression line is much shorter than doing it with raw python code. But it’s important for us to know how the core code works!

This was the last article on Simple Linear Regression.. I hope you guys like it!

*******



You can download the code and some handwritten notes on the derivation from here : https://drive.google.com/open?id=1_stSoY4JaKjiSZqDdVyW8VupATdcVr67

If you have any additional questions, feel free to contact me : shuklapratik22@gmail.com

No comments:

Post a Comment