House Price Prediction Using Machine Learning

1. Introduction

House Price Prediction is one of the most common beginner-level Machine Learning projects. The main goal of this project is to predict the selling price of a house based on important characteristics such as house size, number of bedrooms, and age of the house.

The price of a house is influenced by many different factors. Generally, larger houses may have higher prices, houses with more bedrooms may be more valuable, and newer houses may have higher prices than older houses. Machine Learning can analyze historical housing data and learn the relationship between these features and the selling price.

In this project, historical house data is used to train a Machine Learning model. The dataset contains information about the size of each house, number of bedrooms, age of the house, and its actual selling price. The trained model then uses these patterns to predict the price of a new house.

This is a Supervised Machine Learning problem because the training dataset contains both the input features and the correct house prices. The model learns from these known examples.

Since the target value, house price, is a continuous numerical value, this is a Regression problem. For this project, Linear Regression is used because it is one of the simplest and most commonly used regression algorithms.

2. Objective

The main objective of this project is to build a Machine Learning model that learns from historical house data and predicts the expected price of a new house based on its characteristics.

The project demonstrates the following Machine Learning concepts:

  • Dataset creation

  • Feature selection

  • Target variable selection

  • Multiple Linear Regression

  • Model training

  • Prediction

  • Result interpretation

3. Features Used

The model uses three important house-related features:

House Size

The size of the house is measured in square feet. Larger houses generally have more living space and may have a higher market value.

Number of Bedrooms

The number of bedrooms is another factor that can influence the price. Houses with more bedrooms may be suitable for larger families and can therefore have higher prices.

House Age

The age of the house represents how many years have passed since it was built. In many cases, newer houses may have higher prices, although the effect can vary depending on location and property condition.

The target variable is:

Price – The selling price of the house.

4. Technologies Used

The following technologies are used:

  • Python – Main programming language.

  • Pandas – Used to create and manage the housing dataset.

  • Scikit-learn – Used to implement the Machine Learning model.

  • Linear Regression – Used to predict the continuous house price.

5. Dataset

The project uses a small sample dataset containing five house records.

Each record contains the house size, number of bedrooms, house age, and selling price.

Dataset

   Size  Bedrooms  Age   Price
0  1000          2   20  200000
1  1200          2   15  250000
2  1500          3   10  300000
3  1800          3    8  360000
4  2000          4    5  400000

The model analyzes these examples to learn the relationship between the house characteristics and its price.

6. Working Principle

The system follows a simple Machine Learning workflow.

First, the historical house data is created and converted into a Pandas DataFrame.

The three input features—Size, Bedrooms, and Age—are selected as the independent variables and stored in X.

The Price column is selected as the target variable and stored in y.

A Linear Regression model is then created using Scikit-learn. The model is trained using the historical data. During training, it learns how the three input features are related to the house price.

After training, the details of a new house are provided to the model. In this example, the new house has:

  • Size = 1600 square feet

  • Bedrooms = 3

  • Age = 12 years

The trained model processes these values and predicts the estimated selling price.

7. Python Implementation

The following Python program implements the House Price Prediction system.

# Import required libraries

import pandas as pd
from sklearn.linear_model import LinearRegression

# --------------------------------------------
# Step 1: Create the dataset
# --------------------------------------------

# Sample house data

data = {
    "Size": [1000, 1200, 1500, 1800, 2000],
    "Bedrooms": [2, 2, 3, 3, 4],
    "Age": [20, 15, 10, 8, 5],
    "Price": [200000, 250000, 300000, 360000, 400000]
}

# Convert dictionary into a DataFrame

df = pd.DataFrame(data)

# Display dataset

print("Dataset:")
print(df)

# --------------------------------------------
# Step 2: Select input features (X)
# --------------------------------------------

# Independent variables

X = df[["Size", "Bedrooms", "Age"]]

# --------------------------------------------
# Step 3: Select output variable (y)
# --------------------------------------------

# Dependent variable

y = df["Price"]

# --------------------------------------------
# Step 4: Create the Linear Regression model
# --------------------------------------------

model = LinearRegression()

# --------------------------------------------
# Step 5: Train the model
# --------------------------------------------

model.fit(X, y)

# --------------------------------------------
# Step 6: Predict a new house price
# --------------------------------------------

# House details:
# Size = 1600 sq ft
# Bedrooms = 3
# Age = 12 years

new_house = [[1600, 3, 12]]

predicted_price = model.predict(new_house)

# --------------------------------------------
# Step 7: Display prediction
# --------------------------------------------

print("\nPredicted House Price:")
print(f"${predicted_price[0]:,.2f}")

8. Explanation of the Python Program

The program begins by importing Pandas and the LinearRegression class from Scikit-learn. Pandas is used to organize the housing data, while Linear Regression is used to build the prediction model.

In Step 1, a dictionary containing sample house information is created. The dictionary contains four columns: Size, Bedrooms, Age, and Price. It is then converted into a Pandas DataFrame.

In Step 2, the input features are selected:

X = df[["Size", "Bedrooms", "Age"]]

These three variables are used by the model to predict the house price.

In Step 3, the target variable is selected:

y = df["Price"]

The Price column contains the actual prices that the model needs to learn.

In Step 4, a Linear Regression model is created:

model = LinearRegression()

In Step 5, the model is trained using:

model.fit(X, y)

During the training process, the model learns the relationship between house size, number of bedrooms, house age, and price.

In Step 6, information about a new house is provided:

Size = 1600 sq ft
Bedrooms = 3
Age = 12 years

The trained model uses these values to estimate the selling price.

9. Prediction

Input

Size = 1600 sq ft
Bedrooms = 3
Age = 12 years

Output

Predicted House Price:
$319,000.00

The model predicts that the estimated price of the new house is approximately $319,000.00.

This prediction is based on the patterns learned from the five historical house records.

10. How Linear Regression Works

Since this project uses multiple input features, it is an example of Multiple Linear Regression.

The model attempts to represent the relationship between the house features and price using a mathematical equation such as:

Price = b + w₁(Size) + w₂(Bedrooms) + w₃(Age)

Where:

  • Price = Predicted house price

  • Size = House size

  • Bedrooms = Number of bedrooms

  • Age = Age of the house

  • b = Intercept

  • w₁, w₂, w₃ = Weights learned by the model

During training, the algorithm determines the appropriate weights for each feature based on the historical data.

11. Advantages

The House Price Prediction system has several advantages:

  • Simple and easy to understand.

  • Demonstrates a real-world Machine Learning application.

  • Uses multiple features for prediction.

  • Easy to implement using Python.

  • Helps beginners understand regression.

  • Can be extended with additional housing features.

  • Can provide quick price estimates.

12. Limitations

The main limitation of this project is the very small dataset. Only five sample houses are used to train the model. A real-world house price prediction system would require a much larger dataset containing thousands of properties.

House prices also depend on many factors that are not included in this example. These may include:

  • Location

  • Neighborhood

  • Land size

  • Number of bathrooms

  • Property condition

  • Parking availability

  • Nearby schools

  • Public transportation

  • Local property demand

  • Economic conditions

Because these factors are not included, the prediction should only be considered a simple educational example and not an accurate real-world property valuation.

13. Future Improvements

The system can be improved by collecting a larger and more realistic housing dataset. Additional features such as location, land size, number of bathrooms, property condition, parking spaces, and distance from important facilities can be included.

The dataset can also be divided into training and testing sets to evaluate how well the model performs on unseen data. Regression evaluation metrics such as Mean Absolute Error (MAE), Mean Squared Error (MSE), and R² Score can be used to measure the accuracy of the model.

Other algorithms such as Decision Trees, Random Forest, Gradient Boosting, and Neural Networks can also be tested and compared with Linear Regression.

14. Conclusion

The House Price Prediction Using Machine Learning project demonstrates how historical housing data can be used to predict the price of a new property. The system uses Multiple Linear Regression because the prediction depends on multiple input features: house size, number of bedrooms, and house age.

After training the model using the sample dataset, the system predicts a price of $319,000.00 for a house with a size of 1600 square feet, three bedrooms, and an age of 12 years.

Although the example uses a small dataset and only three features, it provides a useful introduction to supervised learning, regression, feature selection, model training, and prediction. With a larger and more comprehensive dataset, the system could be developed into a more advanced house price prediction application.