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!!

Let’s Go!

(1) Import the required libraries :

Libraries

(2) Read the data file :

Read CSV File

(3) Select useful features from data :

Selected Features

(4) Plot out data on scatter plot :

Plot the Data

(5) Divide data into training and testing data :

Divide Data

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

Constructing Model

(7) Plot the regression line :

Regression Line

(8) Predict the value of co2-emission :

Predicting Values

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

(9) Check model accuracy :

Accuracy of Model

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!

To find more such detailed explanation, visit my blog: patrickstar0110.blogspot.com

(1) Simple Linear Regression Explained With It’s Derivation:
https://youtu.be/1M2-Fq6wl4M

(2)How to Calculate The Accuracy Of A Model In Linear Regression From Scratch :
https://youtu.be/bM3KmaghclY

(3) Simple Linear Regression Using Sklearn :
https://youtu.be/_VGjHF1X9oU

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

Thank You!

--

--