Confused? Between Linear & Multiple Regression and Its Implementation

In this blog post, I would focus on Linear Regression, Multiple Linear Regression or say Multivariate Regression

Linear Regression: Linear regression is a commonly and widely used of all statistical techniques for predictive analysis. These regression estimates are used to explain the relationship between one dependent variable and one or more independent variables.

A relationship between the variables is based on the equation:

Y= mx + b

How does it help:

It helps us to predict the best values based on the available values


Step 1:Import the Libraries

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model
df = read_csv('../input/linear2/Linear2.csv')

Step 2: Plot the Values using matplotlib

import matplotlib.pyplot as plt
%matplotlib inline
plt.scatter(df.area,df.price,color='red',marker ='+')

The prices are dependent on the area of the house

Area(X): Is Independent Variable

Price(Y): Is Dependent Variable Red Markers ‘+’ Represent the actual values in the above table

Step 3: Apply the Linear Regression Model for the above data

#create an object for Linear Regression
reg = linear_model.LinearRegression()
#fit the data into the model[['area']],df.price)

Step 4: Now let’s get the best Line

%matplotlib inline
plt.scatter(df.area,df.price,color='red',marker ='+')

Step5: Let’s Predict the Value if the Area = 2500

Multiple Regression: Multiple linear regression is a model for predicting the value of one dependent variable based on two or more independent variables.

For the example above now let’s assume we also have the values Age: That is how old is the house

Here if you Notice the Area is 4500 but due the Age of the house that is 30 the price of the house is lower than the value of the house with 4000 Area

Area , Age (X): Is Independent Variable, Price(Y): Is Dependent Variable


Now let’s predict the value of the house Where Area: 3000 and Age: 1

Now if you look into the original data set the value of the house with Area 3500 is 500000 But When we predict the value of the house that has Area of 3000 is 549929.7877 which Less than that of 3500 as the Age of the House also helps in determining the value of the house where the Age of 3000 is 1 compare to that of 3500 that is of 12

I have Just tried to Explain the Simple and Multiple Linear Regression and its implementation and how the formula for Linear Regression works

37 views0 comments

Recent Posts

See All

API/Web Service Overview:

So lets start off by learning what exactly is a Web Service? Its a method of communication between two applications or electronic devices over the worldwide web. Here is an example: Consider a flight