Linear Regression- Python

0
142

Linear regression is one of the most commonly used statistical modeling techniques. This article will help you to learn how to implement Simple Linear Regression in Python. At the end of this article, we would have a fair idea about the basic libraries and commands required to for Linear Regression.

Step 1: Import the Libraries. We would use three libraries for this analysis:

  • numpy
  • pyplot
  • pandas

Use below command to import the libraries.

P_LR1

Step 2: Import the data set.

LRP_2

Step 3: Splitting the data set into the Training set and Test set. Provided data set has 30 observations, we would divide it into 20-10 for training and testing purpose.

P_LR3

Step 4: Fitting Simple Linear Regression to the Training set

P_LR4

Step 5: Predicting the Test set results

P_LR5

Step 6: Visualizing the Training set results

P_LR6

below is the output graph.

P_LR7

Step 7: Visualizing the Test set results

P_LR8

below is the output graph.

P_LR9

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here