Site icon Machine Learning Projects

House Price Prediction – USA Housing Data – with source code – easy project – 2023

Machine Learning Projects

House Price Prediction Project proves to be the Hello World of the Machine Learning world. It is a very easy project which simply uses Linear Regression to predict house prices. This is going to be a very short blog, so without any further due, Let’s do it…

Checkout the video here –

Step 1 – Importing required libraries.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score

%matplotlib inline

Step 2 – Reading our input data for House Price Prediction.

customers = pd.read_csv('USA_Housing.csv')
Our input data

Step 3 – Describing our data.

description of our data

Step 4 – Analyzing information from our data.
Info of our data

Step 5 – Plots to visualize data of House Price Prediction.

All numeric columns plots

Step 6 – Scaling our data.

scaler = StandardScaler()


cols = X.columns

X = scaler.fit_transform(X)

Step 7 – Splitting our data for training and test purposes.

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=101)

Step 8 – Training our Linear Regression model for House Price Prediction.

lr = LinearRegression(),y_train)

pred = lr.predict(X_test)

r2 score of our model

Step 9 – Let’s visualize our predictions of House Price Prediction.

sns.scatterplot(x=y_test, y=pred)
y_test vs pred

Step 10 – Plotting the residuals of our House Price Prediction model.


Step 11 – Observe the coefficients.

cdf=pd.DataFrame(lr.coef_, cols, ['coefficients']).sort_values('coefficients',ascending=False)

Download Source Code…

Do let me know if there’s any query regarding this topic by contacting me on email or LinkedIn.

So this is all for this blog folks, thanks for reading it and I hope you are taking something with you after reading this and till the next time…

Read my previous post: WINE QUALITY PREDICTION

Check out my other machine learning projectsdeep learning projectscomputer vision projectsNLP projectsFlask projects at

Exit mobile version