Multiple Linear Regression in machine learning

Objective: By taking multiple values of X(independent variables), we will predict a value of y(dependent variable)

Problem task: Let we have a csv file named as data.csv having four columns like area, bedrooms, age, and price. Here we will predict the value of price by taking the value of area, bedrooms and age by implementing the concept of multiple linear regression.

Here we have considered area, bedrooms, age as X(independent variables) and price as y(dependent variable) #import required libraries

import pandas as pd
importnumpy as np
importmatplotlib.pyplot as plt
importseaborn as sns
fromsklearn import linear_model


#Create a dataframe(here dataframe name is data)
data=pd.read_csv("E:\price.csv")
data

Output:

#Here in data frame, the bedrooms column having NaN value,
#so we have to put a value in that place which is nothing but the median value,
#so we have to find the median value.


import math
median_bedrooms=math.floor(data.bedrooms.median())
median_bedrooms

Output: 3

data.bedrooms=data.bedrooms.fillna(median_bedrooms)
data

Output:
#Create a Linear Regression model

reg=linear_model.LinearRegression()
reg.fit(data[['area','bedrooms','age']],data.price)

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext