What is Simple Linear Regression?

Manik Soni
3 min readSep 25, 2020

--

Simple Linear Regression

Simple Linear Regression is a statistical method that allows seeing the relationship between the dependent and independent variables or we can say a regression model having one independent variable.

The Independent Variable is a variable that helps in the prediction or we can say that helps the dependent variable to make predictions.

The Dependent Variable is a variable that is the outcome or we can say the result which is the actual outcome of the prediction.

Equation of Simple Linear Regression

The above image gives you insight that ‘y’ denotes the dependent variable and ‘x’ denotes an independent variable. It is a simple linear regression equation.

Equation of Simple Linear Regression

In the above equation, ‘Constant’ is a predefined requirement that affects the situation and ‘Coefficient’ is a variable constant that multiple with the independent variable to give the impact or the significance to the dependent variable.

We are using a dataset of the employe's having years of experience and there estimated salary.

DataSet
The intuition of the dataset

Now we are doing the Simple linear Regression analysis on the above dataset.

Step 1. Import the Libraries

Import Libraries

Step 2. Importing the Dataset

Import Dataset

Step 3. Split the data into a matrix of features(X) and the dependent variable(y).

X and y splitting

Step 4. Splitting the matrix of features(X) and dependent variable(y) into training and test set.

Splitting of Test and Training set

Step 5. Fitting a linear model to test and training dataset.

Fitting the linear model

Step 6. Predicting the Test result.

Predict the model
y_test and y_pred results

Step 7. Making the Confusion Matrix to do predictions.

confusion matrix
Confusion Matrix

Confusion Matrix helps to give the accuracy of our model that is the number of false values and true values.

Accuracy of our model

Step 8. Do the visualization of the model.

Visualization
Visualization of the dataset

--

--

No responses yet