0% found this document useful (0 votes)
23 views2 pages

29 ML Multiple Regression

The document outlines a Python program for implementing Multiple Linear Regression using housing data. It includes data preprocessing, model training, and evaluation metrics such as Mean Absolute Error, Mean Squared Error, and Root Mean Squared Error. The program visualizes the relationship between actual and predicted prices using a scatter plot.

Uploaded by

msc932005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

29 ML Multiple Regression

The document outlines a Python program for implementing Multiple Linear Regression using housing data. It includes data preprocessing, model training, and evaluation metrics such as Mean Absolute Error, Mean Squared Error, and Root Mean Squared Error. The program visualizes the relationship between actual and predicted prices using a scatter plot.

Uploaded by

msc932005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Machine Learning Lab 05/09/2024

Experiment 5:

Write a Python program to implement Multiple Linear Regression.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn import metrics
print(Housing.head())
X=Housing[['area','bedrooms','bathrooms','stories','mainroad','guestr
oom','basement','hotwaterheating','airconditioning','parking','prefar
ea','furnishingstatus']]
y=Housing['price']
X_encoded = pd.get_dummies(X, drop_first=True)
X_train,X_test,y_train,y_test=train_test_split(X_encoded,y,test_size=
0.3,random_state=0)
lm=LinearRegression()
lm.fit(X_train,y_train)
predictions=lm.predict(X_test)
plt.scatter(y_test,predictions)
plt.xlabel('Actual Prices')
plt.ylabel('Predicted Prices')
plt.title('Actual vs predicted prices')
plt.show()
print('MAE(Mean Absolute
Error):',metrics.mean_absolute_error(y_test,predictions))
print('MSE(Mear Squared
Error):',metrics.mean_squared_error(y_test,predictions))
print('RSME(Root Mean Squared
Error):',np.sqrt(metrics.mean_squared_error(y_test,predictions)))

Output:
price area bedrooms bathrooms stories mainroad guestroom basement \
0 13300000 7420 4 2 3 yes no no
1 12250000 8960 4 4 4 yes no no
2 12250000 9960 3 2 2 yes no yes
3 12215000 7500 4 2 2 yes no yes
4 11410000 7420 4 1 2 yes yes yes

hotwaterheating airconditioning parking prefarea furnishingstatus


0 no yes 2 yes furnished
1 no yes 3 no furnished
2 no no 2 yes semi-furnished
3 no yes 3 yes furnished
4 no yes 2 no
furnished

22261A6629 21
Machine Learning Lab 05/09/2024

MAE(Mean Absolute Error): 731779.3499846336


MSE(Mear Squared Error): 955428862101.25 RSME

22261A6629 22

You might also like