LINEAR REGRESSION (In 7 Steps)

Kanalsoni
Analytics Vidhya
Published in
2 min readNov 2, 2020

Introduction

In this article, I’m going to represent “How to Build your own Linear Regression Model in just 7 Steps!”

Linear Regression: Linear Regression represents some relationship between the dependent variable (y) and the independent variable (x).

It is used to classify the data.

We’re going to implement Linear Regression in Python in just 7 steps:

(You can find the dataset used to build this model here)

Step 1: Import the required libraries

Here, we have imported Pandas, NumPy, math, statsmodels, matplotlib and sklearn libraries to work with.

Step 2: Read the data using Pandas library

We’ll use pd.read_csv function to read the data.

Step 3: Distribute the data into X and Y axis

We’ll distribute the columns of the data into X and Y axis to visualize and predict the model.

Step 4: Split the data into train and test set

We’ll split the data into the ratio of (7:3). That means, training data=70% and test data=30%.

Step 5: Fit the model and make prediction

We’ll then fit the model using fit() method and will predict the data to build our model.

Step 6: Visualize the data using matplotlib

We’ll visualize the data of the model using matplotlib library to have a better vision

Step 7: Calculate the accuracy of the model

We’ll calculate and print the accuracy of our model which will tell us how precise our predicted model is.

Output:

Output for concrete.csv data

Conclusion

Thus, we can conclude that Linear Regression is a strong tool in Machine Learning which is used to build and analyze the models based on continuous variables representing the relationship between x and y.

--

--