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.

Step 2: Import the data set.

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.

Step 4: Fitting Simple Linear Regression to the Training set

Step 5: Predicting the Test set results

Step 6: Visualizing the Training set results

below is the output graph.

Step 7: Visualizing the Test set results

below is the output graph.