Simple Linear Regression Implementation

Original article was published on Artificial Intelligence on Medium

Simple Linear Regression Implementation

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