• For any query, contact us at
  • +91-9872993883
  • +91-8283824812
  • info@ris-ai.com

Predict User Buying Housing Price On The Bases Of Salary

The competition goal is to predict sale prices for homes on the bases of salary earned. As this project predict the value of home that the person can buy on entering person salary.

We firstly import necessary library for this project

In [1]:
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt

Now we read CSV file in which contains data for predicting house price

In [2]:
housing = pd.read_csv('housing.csv')

We take median_income and median_house_value column and divide them in two ration of 80 and 20% by giving test_size = 0.2 Which defines a and y trainset and x and y test_set

In [3]:
xtrain_set, xtest_set, ytrain_set, ytest_set = train_test_split(housing.median_income, housing.median_house_value, test_size=0.2)

Here, we call Linear Regression in lin_reg variable

In [4]:
lin_reg = LinearRegression()

By using LinearRegression we train our model to predict the model as we get xtrain_set value to be fit with ytrain_set value

In [5]:
lin_reg.fit(np.array(xtrain_set).reshape(-1,1), ytrain_set)
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)

We input salary so that we can predict price of house

In [6]:
print("Enter Your Income")

salary=float(input("Income: "))
Enter Your Income
Income: 7.2574

Our model will predict the value with xtest_set i.e. salary entered for ytrain_set

In [7]:
predictions = lin_reg.predict(np.array(salary).reshape(-1,1))

Here we get result of prediction of house price i.e. ytest_set on the bases of salary

In [8]:
print("you will buy home with approx rate of:" )
you will buy home with approx rate of:

Here we can check the difference between value which model predict and the ytest_set which is store in result variable

In [9]:
result = predictions-ytest_set

You can see the hist graph for result value

In [10]:
(array([223., 105., 126., 246., 342., 579., 736., 800., 762., 209.]),
 array([-151611.21291663, -103361.11291663,  -55111.01291663,
          -6860.91291663,   41389.18708337,   89639.28708337,
         137889.38708337,  186139.48708337,  234389.58708337,
         282639.68708337,  330889.78708337]),
 <a list of 10 Patch objects>)
House Budget Prediction Based on Salary