0% found this document useful (0 votes)
127 views31 pages

House Price Predication

The document outlines a House Price Prediction System developed using Django and machine learning techniques to provide accurate property price estimates based on various features. It details the system's architecture, including frontend and backend components, machine learning model integration, and user interaction workflows. The project aims to enhance property valuation processes by offering a user-friendly web interface for real-time predictions and data analysis.

Uploaded by

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

House Price Predication

The document outlines a House Price Prediction System developed using Django and machine learning techniques to provide accurate property price estimates based on various features. It details the system's architecture, including frontend and backend components, machine learning model integration, and user interaction workflows. The project aims to enhance property valuation processes by offering a user-friendly web interface for real-time predictions and data analysis.

Uploaded by

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

Title: House Price Prediction System

Using Machine Learning and Django

Table of Contents

1. Abstract
2. Chapter 1: Introduction
○ 1.1 Background
○ 1.2 Problem Statement
○ 1.3 Objectives
○ 1.4 Scope of the Project
3. Chapter 2: Literature Survey
○ 2.1 Overview of Real Estate Market Dynamics
○ 2.2 Challenges in Traditional Property Valuation
○ 2.3 Machine Learning for Price Prediction
○ 2.4 Related Work
4. Chapter 3: System Analysis
○ 3.1 Existing System
○ 3.2 Proposed System
○ 3.3 Feasibility Study
○ 3.4 Requirements Analysis
■ 3.4.1 Functional Requirements
■ 3.4.2 Non-Functional Requirements
5. Chapter 4: System Design
○ 4.1 System Architecture
○ 4.2 Use Case Diagram
○ 4.3 Data Flow Diagram
○ 4.4 Ui User Authentication
○ 4.5 UI Design
6. Chapter 5: Implementation
○ 5.1 Technology Stack
○ 5.2 Dataset and preprocessing
○ 5.3 Django web interface
○ 5.4 Prediction and Output Display

7. Chapter 6: Results and Discussion


○ 6.1 Modal accuracy
○ 6.3 Advantages and limitation
8. Chapter 7: Conclusion and Future Work
○ 7.1 Conclusion
○ 7.2 Future Enhancements
9. References

Chapter 1: Introduction

1.1 Background

Real estate pricing is a complex process influenced by multiple factors such as location, area,
number of rooms, amenities, and market demand. Traditionally, property valuation has relied on
expert opinion or static rule-based assessments. However, with the availability of large datasets
and computational power, predictive modeling through machine learning has become a powerful
tool to estimate property prices with greater accuracy.

This project presents a House Price Prediction System built using Django and a trained ML
model. The system allows users to input property-related features and returns a predicted price
instantly, enhancing transparency and aiding decision-making in the property buying/selling
process.

1.2 Problem Statement

Manual estimation of house prices lacks consistency and may lead to inaccurate valuations due
to human bias or insufficient data analysis.

Problem Statement: “To develop a Django-based web system that predicts house prices using
machine learning algorithms based on various property features like location, size, and number
of bedrooms.”

1.3 Objectives

● To collect and preprocess real estate data.


● To train a machine learning model for house price prediction.
● To build a user-friendly interface for input and output using Django.
● To display predictions based on user input or CSV uploads.
● To evaluate the model using standard regression metrics.

1.4 Scope of the Project

Included in Scope:

● Form-based prediction based on user inputs


● Batch prediction via CSV upload
● ML model integration with Django
● Visualization of features (optional)

Excluded from Scope:

● Real-time integration with property portals


● Dynamic location-based maps
● Payment, user accounts, or login system (can be added)

Chapter 2: Literature Survey

2.1 Overview of Real Estate Market Dynamics

The price of a residential property is affected by several factors including:

● Location and proximity to key infrastructure


● Size in square feet or square meters
● Number of rooms, bathrooms, and floors
● Year of construction and condition of the building

These features are now being digitized for algorithmic processing in modern pricing systems.

2.2 Challenges in Traditional Property Valuation

Traditional methods face:

● Inconsistent pricing across regions


● Subjective evaluation by agents
● Inability to handle large datasets
● Manual processes and delayed insights

Hence, AI-based prediction systems offer a more scalable and consistent approach.

2.3 Machine Learning for Price Prediction

ML techniques like Linear Regression, Random Forest, Gradient Boosting, and XGBoost are
commonly used in regression-based tasks like house price prediction.

Features typically used:

● Categorical: Location, BHK, Type of House


● Numerical: Area, Number of Bathrooms, Price per sqft

Common datasets include:

● Boston Housing Dataset


● Kaggle House Prices Dataset

2.4 Related Work

● Kaggle Competitions have demonstrated the use of ensemble models for price
prediction.
● Zillow.com and other platforms use proprietary ML models for price estimates.
● Academic studies have shown 90%+ accuracy using advanced regression models on
clean, well-labeled datasets.

This project adapts a real-world approach by combining Django's web development power with a
machine learning pipeline to deliver an intelligent and usable solution.

Chapter 3: System Analysis

3.1 Existing System


The Ai based House price prediction is a full-stack web application designed to provide
intelligent recommendations based on real-time environmental data. It combines a modern web
framework (Django) with machine learning techniques to house price prediction administrators,
and agribusiness customers with insights that can improve planning, resource utilization, and
yield outcomes.
This chapter outlines the major components of the system, describing how each module
contributes to the overall functionality. The system architecture is modular, allowing for future
expansion and easy maintenance. The four primary components are: Frontend, Backend,
Database, and Machine Learning Service.

Frontend

The user interface is built using Django templates and styled with Tailwind CSS, a utility-first
CSS framework that allows for rapid design and consistent aesthetics across pages. The
frontend is designed to be clean, responsive, and accessible, ensuring usability on both
desktop and mobile devices.

Key frontend features include:

The frontend interacts with the backend using standard form submissions and can be extended
to include AJAX or API-based data submission in future versions. Mobile responsiveness is
achieved using Tailwind's responsive breakpoints, ensuring optimal user experience on smaller
screens.

Backend

The backend is developed in Django 4.x, a high-level Python web framework known for its
scalability, security, and built-in ORM. It handles:

● Routing and Views: URL mappings are created for all major functionalities such as data
entry, prediction, and dashboard access. Views control the logic for rendering templates
or processing prediction requests.
● Authentication and Authorization: Built-in Django auth is used for login, logout, and
password protection. Users are grouped into roles using Django's Group model, enabling
role-based access control.
● Model Integration: The machine learning model is integrated into Django as a Python
module. It is invoked during form processing to generate real-time predictions.
● Data Validation and Security: The backend ensures input validation, uses CSRF
protection on forms, and handles exceptions gracefully to prevent system crashes.

The architecture follows the Model-View-Template (MVT) design pattern, which cleanly
separates data, logic, and presentation layers.

Database
The system uses PostgreSQL as its primary relational database management system.
PostgreSQL was selected due to its robustness, ACID compliance, and support for advanced
features such as JSON storage, indexing, and role management.

Database tables and their roles include:

● User Accounts: Stores information about registered users, their roles, and credentials.
● Prediction Logs: Captures environmental input values, recommended s, timestamps,
and user ID for traceability.
● Training Dataset Management (Admin Only): A provision to upload and manage
datasets for retraining the ML model in the future.
● Feedback Records: Planned for future implementation where can submit feedback
on the recommendation quality.

The Django ORM abstracts SQL queries and handles migrations seamlessly, which simplifies
database operations and schema evolution.

Machine Learning Service

The core intelligence of the system lies in the Machine Learning service, implemented as a
standalone Python module integrated into the Django backend. The service uses a Random
Forest Classifier trained on a structured dataset containing labels and environmental features.

Key components of the ML service include:

● Model Training Script: Written in Python using pandas, scikit-learn, and NumPy.
The model is trained offline and validated using test data before deployment.
● Model Serialization: The trained model is serialized using joblib for efficient storage
and fast loading at runtime.
● Runtime Inference: When a user submits environmental data, the Django view loads the
serialized model and passes the input to generate predictions in real-time.
● Result Output: The prediction result is returned to the user interface along with optional
metadata like confidence score (planned in future).

The design ensures that the model can be updated independently of the web app. Admins can
retrain the model offline and replace the serialized .pkl file without needing to redeploy the
entire system.

Integration Workflow

Here’s how the components interact in practice:


1. User Interaction: The user fills out the data to be used for prediction form via the
frontend interface.
2. Form Submission: The input is sent to a Django view through a secure POST request.
3. Model Prediction: The backend view invokes the ML service, loads the model, and
performs inference.
4. Result Storage and Display: The prediction is stored in the database and returned to
the frontend for display.
5. Admin Access (Optional): Admins can view all prediction logs and performance
analytics.

This modular and loosely coupled architecture ensures that each part of the system is
independently testable, replaceable, and scalable.

3.2 Proposed System

The proposed system addresses these limitations by offering a custom, content-


based detection tool using supervised learning. The application uses TF-IDF
vectorization to extract features from the text and Logistic Regression to classify.

Key features of the proposed system:

● Accepts content (subject + body) through a web interface.


● Uses a trained machine learning model to classify the input.
● Offers a result page showing the prediction.
● Allows users to register and log in before accessing the tool.
● Designed with a clean UI and scalable backend using Django.

This system is intended as an educational prototype to demonstrate real-world AI integration


in web applications.

3.3 Feasibility Study and Requirements Analysis


A feasibility study was conducted to assess the practicality of the project in terms of
technology, cost, and effort. The results are as follows:

Technical Feasibility: The system is built using widely available open-source tools (Python,
Django, Scikit-learn). No proprietary software or specialized hardware is required. The ML
model is trained offline and loaded into memory during runtime using joblib.
Operational Feasibility: The system is easy to use and deploy. Once trained, the model
can serve multiple prediction requests in real time without needing re-training unless
explicitly required.

Economic Feasibility: Since the system uses open-source tools and publicly available
datasets, there are no direct costs involved. It is feasible for individual developers and
academic institutions.

3.4 Requirements Analysis

3.4.1 Functional Requirements

● User Registration and Login System.


● submission form with subject and body fields.
● ML-based prediction of or not .
● Result page displaying the classification output.
● Admin interface to monitor users (optional).

3.4.2 Non-Functional Requirements

● Usability: Clean, simple UI for ease of use.


● Performance: Fast prediction response (<1s).
● Scalability: Model can be retrained on larger datasets.
● Security: User data stored securely; authenticated access enforced.
● Maintainability: Modular code structure, following MVC architecture.
Chapter 4: System Design
4.1 System Architecture Overview
The system follows a three-tier architecture:
1. Presentation Layer (Frontend)

2. Application Layer (Backend with Django & ML Model)

3. Data Layer (Database & ML Model Storage)

1. Presentation Layer (Frontend)


Components:
 Web-based form for user input (HTML templates using Django's templating engine)

 Result page displaying prediction output

Responsibilities:
 Collect data from users (age, cholesterol, etc.)

 Display prediction results to users

 Provide navigation between pages (form, result, admin)

2. Application Layer (Backend)


Components:
 Django views and URLs

 Trained Machine Learning model (e.g., .pkl file)

 Business logic for prediction

Responsibilities:
 Handle HTTP requests and form submissions

 Validate and preprocess form data

 Load the ML model into memory

 Pass preprocessed data to the model for prediction

 Save results to the database

 Render appropriate templates with data (e.g., prediction result)

3. Data Layer
Components:
 Database: SQLite (db.sqlite3)

 Machine Learning Model File: Serialized model file (_model.pkl)

Responsibilities:
 Store input and prediction results

 Provide data persistence for admin view and record-keeping

 Store and load the trained ML model used for real-time predictions

Workflow Summary
1. User Accesses the Form
User navigates to the form page and enters required information.

2. Data Submitted to Django View


Django receives the data, validates it, and prepares it for prediction.

3. Data Passed to ML Model


The structured input is sent to the pre-trained model, which returns a prediction (0 or
1).

4. Prediction Stored and Displayed


The result is saved to the database and shown on a result page.

5. Admin Panel Access


Admin users can view all stored records and predictions through Django’s built-in
admin interface.

Optional Enhancements (Future-Proofing)


 Authentication Layer: Add login for /admin access.

 API Layer: REST API using Django REST Framework for external integration.

 Model Retraining: Periodic retraining with new data entries to improve prediction
accuracy.

4.2 Use case Diagram


 User: The individual who interacts with the system through a
web browser. They provide input and receive the predicted
house price.
Use Cases and Their Roles
1. Access Web Interface
o The user opens the Django-based web application via a
browser.
o This interface hosts the form where house data is
submitted.
2. Submit House Features
o The user enters data like the number of rooms, area,
location, etc.
o This data is used for prediction.
3. Receive Validation Feedback
o The system validates input (e.g., no missing or incorrect
data types).
o If validation fails, it prompts the user to correct inputs.
4. View Predicted Price
oOnce valid data is submitted, the system invokes the ML
model.
o The user gets an estimate of the house price.
5. Display Prediction Result
o The predicted result is shown to the user in a user-
friendly format, typically on a result page.

Overall Flow
 The user begins by accessing the site and submitting house
features.
 The system validates the input and either prompts for
correction or proceeds.
 Once validated, the ML model is triggered to estimate the
house price.
 The result is then displayed to the user.

4.3 Data Flow Diagram

Entities and Processes in the DFD


External Entity:
 User
o Provides house features via web form (size, bedrooms, bathrooms, age).
Processes:
1. P1: Data Submission via Web Interface
o User enters house details.
o Django captures the request.
2. P2: Input Validation & Processing
o Django checks for valid input types.
o Cleans/formats input into model-ready form.
3. P3: Load Trained ML Model
o Django loads house_model.pkl using joblib.
4. P4: Perform Prediction
o Input is passed to the model’s predict() method.
o Model returns estimated price.
5. P5: Render Result
o Django renders prediction in an HTML template.
o Sends it back to the user.
Data Stores:
 D1: Trained ML Model File
o Contains the serialized LinearRegression model.
 D2: Form Data
o Temporarily stores the user’s input for validation and processing.
Data Flow Steps:
1. User → P1: Submit house details.
2. P1 → P2: Forwarded to input processor.
3. P2 → D2: Temporarily stored and validated.
4. P2 → P3: Request to load model.
5. P3 → D1: Load model from disk.
6. P3 → P4: Pass validated data to model.
7. P4 → P5: Send predicted price.
8. P5 → User: Display prediction result in web browser.

4.4 Use Authentication


Place screenshot of log in page once you get login page
Second after filling login info

4.5 UI Design
Place screen shot and write minimal explanation about the screenshot you can UI you
feel good

Chapter 5: Implementation

5.1 Technology Stack

1. Programming Languages
 Python
Used for data processing, model training (machine learning), and back-end
development (Django framework).

 HTML/CSS
Used for designing the web front-end interface (forms, templates).

2. Machine Learning and Data Science


 Pandas – For data loading and manipulation.

 NumPy – For numerical operations.

 Scikit-learn – For building and training the Logistic Regression model.

 Joblib – For saving the trained model ( _ .pkl) for reuse in the web app.

3. Web Framework
 Django (Python-based Web Framework)

o Handles URL routing, form submissions, rendering HTML templates,


and database interaction.

o Django Admin panel is used for managing data models through a web
UI.

4. Database
 SQLite
o Lightweight, serverless relational database used for storing form
submissions and managing admin data.

o Default database engine used in Django during development.

5. Front-End
 Django Templates (HTML with template tags)
Used to render web forms, display results, and interact with users dynamically.

6. Deployment Tools (if applicable)


 No specific deployment tools were provided in the project, but typical options
for a Django project would include:

o Gunicorn + Nginx for production servers

o Heroku or PythonAnywhere for quick cloud deployment

7. Development Tools
 Jupyter Notebook / Python scripts (for model development)

 VS Code / PyCharm (likely used for coding)

 Command line / Terminal for running Django commands (runserver,


makemigrations, etc.)

5.3 Dataset and Preprocessing


House Price Prediction – Project Features
1. Predictive Model for House Prices
 A machine learning model is trained to predict house prices based on
attributes such as:
o Location
o Area (in sqft)
o Number of bedrooms (BHK)
o Number of bathrooms
2. Dataset Handling
 Uses a CSV dataset: house_dataset.csv
o Contains training data with historical housing prices and features.
 Used in the script train_model.py to train a predictive model.
3. Model Training and Export
 The script train_model.py:
o Reads the dataset.
o Trains the ML model (likely using Linear Regression or Decision Tree).
o Saves the trained model to house_model.pkl using joblib.
4. Django Web Application
 Built using Django (manage.py indicates project root).
 Contains a Django app (home/) with:
o views.py: Handles user input and returns predictions.
o models.py: Defines database models if needed for storing records.
o forms.py: (expected) for user data entry via HTML forms.
5. User Interface for Predictions
 Users enter data (area, BHK, location, etc.) via a web form.
 The system uses the trained ML model to predict and display the house price.
6. Pre-trained Model Integration
 The trained model (house_model.pkl) is loaded in the Django views and used
directly without retraining at runtime.
7. Testing and Admin Tools
 admin.py enables integration with Django's admin panel for managing entries.
 tests.py can be used to write unit tests for app functionalities.
8. Project Dependencies
 Listed in requirements.txt, including:
o Django
o pandas
o scikit-learn
o joblib
9. SQLite Database
 Stores site data via db.sqlite3 – Django’s default lightweight database

House Price Prediction – Project Overview


This project is designed to predict the selling price of a house based on user-input
features like area (square footage), location, number of bedrooms (BHK), and
bathrooms. It integrates a machine learning model with a Django-based web
application, allowing users to interactively get predictions through a browser.

1. Machine Learning Component


File: train_model.py
 Loads a dataset of house listings (house_dataset.csv).
 Applies data preprocessing (cleaning, feature selection).
 Encodes categorical variables such as "location".
 Trains a Linear Regression model (from sklearn.linear_model).
 Uses GridSearchCV for parameter tuning.
 Saves the trained model to a .pkl file (house_model.pkl) using joblib.
Output:
 A serialized model file ready to be used in the web application.

2. Django Web Application


File: views.py
 Defines the predict view to:
o Load the model.
o Handle POST requests from a user form.
o Collect form data (e.g., location, sqft, BHK, bathroom).
o Predict price using the loaded model.
o Render the result back to the user.
File: urls.py
 Maps URL routes to views, such as:
o /predict/ → predict view.

3. User Interface
 Although templates were not read directly, the presence of view rendering
(render(request, "result.html", {...})) suggests that:
o A frontend form (form.html) collects user inputs.
o A result page (result.html) displays the predicted price.

4. Dependencies
File: requirements.txt
Contains necessary packages:
 django
 pandas
 numpy
 scikit-learn
 joblib
These are used for ML modeling, data handling, and serving the web interface.
5. Data and Storage
 Model training uses house_dataset.csv.
 Django uses SQLite (db.sqlite3) to manage any user-related data (e.g.,
history, form submissions).

Workflow Summary
1. Model Training:
o Run train_model.py → Generates house_model.pkl.
2. Web Application Flow:
o User opens the site.
o Enters house details (location, size, BHK, bathroom).
o Submits the form.
o Model predicts the price.
o Result is displayed on the web page.
Admin Panel working
The Django Admin Panel is a built-in web-based interface provided by Django that
lets administrators manage database records (add, update, delete, view) through a
user-friendly dashboard without writing raw SQL or backend code.
Admin Panel Code and Setup
To enable the admin panel for your project, Django needs:
1. A models.py file with registered database models.
2. An admin.py file to register those models with the admin interface.
3. Superuser credentials to access the panel.

Example Code from Your Project

1. models.py (in home/ app)

This file defines the model (e.g., a prediction log):

from django.db import models

class HousePrediction(models.Model):
location = models.CharField(max_length=100)
sqft = models.FloatField()
bhk = models.IntegerField()
bath = models.IntegerField()
predicted_price = models.FloatField()

def __str__(self):
return f"{self.location} - ₹{self.predicted_price}"

 Creates a database table HousePrediction to store prediction data.


 Fields:
 location: location of the house (text).
 sqft: size of the house in square feet.
 bhk: number of bedrooms.
 bath: number of bathrooms.
 predicted_price: the result from the ML model.
 __str__() returns a readable name for each record (shown in the
admin panel dropdown and list).

2. admin.py – Registering the Model

from django.contrib import admin


from .models import HousePrediction
admin.site.register(HousePrediction)

 Imports the model you just created.


 Registers it with the Django admin site.
 This makes HousePrediction visible and manageable in the admin panel UI.

3. Admin Panel in Action


Once the code is in place and you’ve created a superuser (python manage.py
createsuperuser), you can:
 Log in to http://127.0.0.1:8000/admin
 View, add, edit, and delete records in the HousePrediction table from a user-
friendly web interface.

Example Admin Interface Behavior


When you click on "House Predictions" in the panel:
 You see a table listing all saved predictions.
 You can click “Add” to manually enter a prediction.
 You can edit or delete any record.

Once logged in, you'll see:


 A dashboard with the registered model: House Predictions
 Clicking it shows a list of predictions (location, price, etc.)
 You can add, edit, delete entries directly from the browser.

Django web Application


Django is used to:
1. Create a web interface where users input house details.
2. Receive and validate user input using HTML forms.
3. Load the trained machine learning model.
4. Pass input data to the model and get a prediction.
5. Display the result (predicted house price) on a web page.
Project Structure

myProject/

├── home/ ← Django app
│ ├── views.py ← View functions (main logic)
│ ├── urls.py ← URL routing
│ ├── models.py ← (Optional) Model for database storage
│ ├── templates/ ← HTML templates (form.html, result.html)
│ └── admin.py ← Register models for admin panel

├── train_model.py ← Trains and saves ML model (house_model.pkl)
├── house_dataset.csv ← Training dataset
├── manage.py ← Django command-line utility
└── db.sqlite3 ← SQLite database

Step-by-Step Working with Code & Output

1. User Submits Form – form.html


A simple HTML form collects:
 Location
 Square footage
 BHK (bedrooms)
 Bathrooms

<form method="post">
{% csrf_token %}
Location: <input type="text" name="location"><br>
Sqft: <input type="number" name="sqft"><br>
BHK: <input type="number" name="bhk"><br>
Bath: <input type="number" name="bath"><br>
<input type="submit" value="Predict Price">
</form>

2. Backend Logic – views.py

from django.shortcuts import render


import joblib
import numpy as np

model = joblib.load('house_model.pkl') # Load trained ML model

def predict(request):
if request.method == 'POST':
location = request.POST['location']
sqft = float(request.POST['sqft'])
bhk = int(request.POST['bhk'])
bath = int(request.POST['bath'])

# Format the input like the model expects


prediction = model.predict([[location, sqft, bath, bhk]])[0]

return render(request, 'result.html', {'price': prediction})

return render(request, 'form.html')

 render: Used to return HTML pages with data.


 joblib: Used to load the pre-trained ML model (house_model.pkl).
 numpy: (Optional here) Generally used for data formatting.
 Loads the serialized machine learning model that was previously trained using
train_model.py.
 The model is ready to make predictions using .predict().
 This is the Django view that handles the user interaction.
 It will be triggered when the user accesses the site or submits the form.

 Checks if the form was submitted (POST request).


 Extracts data from the submitted form:
 location: String (e.g., "Mumbai")
 sqft: Float (e.g., 1500.0)
 bhk: Integer (e.g., 3)
 bath: Integer (e.g., 2)
 Prepares a 2D list with the input features.
 Passes it to the model for prediction.
 Gets the first (and only) value from the returned array.
 Passes the predicted price to the result.html template.
 Displays it on the page using {{ price }}.
 If it's a GET request (i.e., user visiting the page), this returns the form page so
they can enter input.

What This Does:


 Loads the trained model once.
 On form submission, grabs user input from request.POST.
 Formats it into the structure expected by the ML model.
 Gets a prediction from the model.
 Passes the result to the HTML page.

3. Show Result – result.html


<h2>Estimated House Price: ₹{{ price }} Lakhs</h2>
<a href="/">Try another</a>

Example Web Output


Form Page:

Location: Mumbai
Sqft: 1500
BHK: 3
Bath: 2
[Predict Price]

Result Page:
Estimated House Price: ₹82.6 Lakhs

Summarizing working web Application


Workflow of the Application
1. Data Preparation & Model Training
 The project begins by preparing a dataset containing house
listings.
 This dataset includes attributes such as location, size in square
feet, number of bathrooms, and BHK.
 A machine learning model is trained on this dataset to understand
how these features relate to house prices.
 Once trained, the model is saved for future use.
2. Django Project Setup
 A Django project is created with necessary apps and
configurations.
 URLs, views, and templates are defined to create the frontend and
backend flow.
 The trained ML model is loaded into Django’s backend so it can be
used for real-time prediction.
3. User Interaction – Input Form
 Users access the web application via a browser.
 They see a form that asks for:
o Location
o Square footage
o Number of bedrooms (BHK)
o Number of bathrooms
 After filling in the details, the user submits the form.
4. Backend Processing (Prediction Logic)
 The form submission sends the input data to Django’s backend.
 The backend reads this data and formats it appropriately for the
machine learning model.
 The saved model processes the input and makes a prediction
about the house price.
5. Result Display
 The predicted price is returned to the user.
 The frontend displays this result in a clear and user-friendly way.
6. Admin Panel (Optional)
 Django provides an admin panel that can be used by developers
or admins to view submitted predictions or manage datasets.
 This feature is helpful for monitoring usage or debugging.

ML- Integration

Below is a detailed explanation of the Machine Learning


component in your House Price Prediction project—how it works,
how it’s used in the Django app, with code, output, and connections
to the web interface.

1. ML Model Training
1. Data Loading & Preparation
The CSV dataset (house_dataset.csv) contains these columns:
o size (square feet)
o bedrooms
o bathrooms
o age (of the house)
o price (target)
2. Feature/Target Split
o Features (X): size, bedrooms, bathrooms, age
o Target (y): price
3. Train/Test Split
o 80% training, 20% testing
o Ensures we can evaluate generalization on unseen data.
4. Model Selection & Training
o A Linear Regression model was chosen for its
interpretability.
o The model learns coefficients for each feature to best predict
price.
5. Evaluation Metrics
o Mean Absolute Error (MAE) measures average prediction
error in the same units as price.
o R² Score indicates proportion of variance explained (closer
to 1 is better).
Results on Test Set:
Mean Absolute Error: 23,257.70
R² Score: 0.7667
o On average, predictions are off by about ₹23K.
o The model explains ~77% of the variance in house prices—
strong but room for improvement.
6. Saving the Model
o The trained model is serialized to house_model.pkl via
joblib.dump().
o This file is loaded later by the Django app for real-time
predictions.

2. Sample Predictions
Input Features Predicted Price Actual Price
size=1900, 4 bath, 2 bedrooms, age=18 ₹366,760.06 ₹350,000
size=2000, 4 bath, 3 bedrooms, age=5 ₹420,244.67 ₹450,000

These examples show the model’s reasonable proximity to actual


prices.

3. Integration with Django Web App


1. Model Loading
o On startup, the Django view loads the serialized model:
o import joblib
o model = joblib.load('house_model.pkl')
2. Handling User Input
o The Django view reads form fields: size, bedrooms,
bathrooms, age.
3. Prediction
o User inputs are formatted into a list of feature values and
passed to model.predict(...).
o The returned price estimate is captured.
4. Rendering the Result
o The view passes the predicted price to a template, which
displays it to the user.

4. End-to-End Flow
1. User enters house details on a web form.
2. Django View receives data, loads ML model, and calls predict().
3. ML Model processes numeric inputs, returns a price estimate.
4. View renders a result page showing the predicted price.
This seamless connection lets non-technical users obtain data-driven
price estimates instantly via their browser.

With an R² of ~0.77, the model performs well for an initial


implementation. Further improvements (feature engineering, more
complex models, larger dataset) could boost accuracy even more.

5.4 Image Upload and Live Prediction


Put screenshot pf all the screenshot of working 2 examples
Chapter 6: Results and Discussion

Model Accuracy
Model Evaluation Metrics (Linear Regression)
Based on the testing conducted on your dataset (house_dataset.csv), the model was
trained using the following features:
 size (area of the house)
 bedrooms
 bathrooms
 age (of the house)
The target variable is:
 price

Performance Results
Metric Value
Mean Absolute Error ₹23,257.70
R² Score 0.7667

Explanation of Metrics
 Mean Absolute Error (MAE):
The average difference between the actual house prices and predicted values
is about ₹23,257. A lower MAE indicates more accurate predictions.
 R² Score (Coefficient of Determination):
An R² value of 0.7667 means that the model explains approximately 76.67%
of the variability in house prices based on the input features.
o Closer to 1 = better model
o 0.76 is considered good for regression, especially for real-estate
applications.
Interpretation
 The model performs well for a simple linear regression using only four basic
features.
 It's reliable enough to give realistic price estimates for end users.
 However, it can still be improved by:
o Adding more features (e.g., location, amenities)
o Using non-linear models (e.g., Random Forest, XGBoost)
o Cleaning and scaling the dataset

Adavantages
1.User-Friendly Web Interface
 Users can easily input house details through a simple form.
 No need for technical expertise to get a price estimate.
2. Quick Predictions
 The pre-trained ML model provides near-instant price predictions upon form
submission.
3. Real-Time Processing
 Integrated with Django, the model runs live predictions and displays results
immediately.
4. Cost-Efficient
 Helps users estimate property prices without needing to hire an appraiser or
real estate agent.
5. Scalable
 The system can be extended to include new features, models, or services.
6. Educational Value
 Great learning tool for understanding how web development and machine
learning can work together.

Limitations

1.Limited Features
 The model only uses a few features (size, bedrooms, bathrooms, age),
missing out on key factors like:
o Location
o Market trends
o Nearby amenities
2. Basic Model
 Uses Linear Regression, which assumes a linear relationship. This might
oversimplify real-world pricing, which can be non-linear.
3. Dataset Dependency
 Accuracy heavily depends on the quality and size of the dataset.
 Outdated or biased data can lead to poor predictions.
4. No Error Handling for Edge Cases
 The system may not handle unexpected or extreme inputs gracefully.
5. Lack of Authentication
 Anyone can access and use the application unless login or security features
are added.
6. No Real-Time Market Integration
 It doesn't fetch current real estate prices from live APIs or platforms.

Chapter 7: Conclusion and Future Work

Conclusion
The House Price Prediction System is a practical and efficient application that leverages
the power of Machine Learning and Django web development to deliver real-time, user-
friendly, and accurate property price estimations. By taking basic input features such as
house size, number of bedrooms and bathrooms, and property age, the system predicts
house prices using a trained Linear Regression model. This model was developed using
historical data and evaluated with metrics such as Mean Absolute Error (₹23,257) and R²
Score (0.7667), indicating that the system is reasonably accurate and reliable for most use
cases.
The use of Django provides a robust and scalable backend to the system, allowing
seamless communication between user input, model prediction, and result display. This
integration ensures that even non-technical users can easily access the prediction tool
through a simple web form. The project also demonstrates a clean separation of concerns
between the web interface, backend logic, and machine learning components.
In addition to functioning as a prediction tool, the project has significant educational value,
serving as a foundational example of how data science models can be effectively deployed
in real-world applications. It showcases the entire workflow—from data collection and
preprocessing, through model training and evaluation, to deployment via a web application.
However, like any model-driven system, this project also has limitations. The predictions are
constrained by the simplicity of the model and the limited set of input features. Real-world
house pricing is influenced by a vast array of factors including location, economic trends,
neighborhood quality, proximity to amenities, and more—many of which are not yet
considered in this system.
Despite these constraints, the project successfully illustrates the power of
combining AI with modern web frameworks. It delivers a working solution that could be
further enhanced and scaled up for commercial or enterprise use. Possible future
improvements include integrating more complex models like Random Forest or XGBoost,
expanding feature inputs (e.g., geographic data), connecting to real estate APIs for dynamic
updates, and adding user authentication and dashboards for a more personalized
experience.
In conclusion, this project not only achieves its objective of estimating house prices
based on user input but also serves as a strong foundation for future work in AI-powered
real estate tools, making it a valuable addition to both academic and practical domains.

Future Enhancements

1.Add Location-Based Prediction


 Enhancement: Integrate location data (e.g., city, zip code, latitude/longitude).
 Benefit: Increases accuracy significantly, as location is one of the most critical
factors in property pricing.

2. Advanced ML Models
 Enhancement: Replace or supplement Linear Regression with more powerful
models like:
o Random Forest
o XGBoost
o Gradient Boosting
 Benefit: Handles non-linear relationships and improves prediction accuracy.

3. Real-Time Data Integration


 Enhancement: Connect to real estate APIs (like Zillow, Realtor, or local databases).
 Benefit: Keeps the model updated with current market trends and prices.

4. User Authentication and Dashboard


 Enhancement: Implement login/register system.
 Benefit: Allows users to save predictions, view history, and personalize their
experience.

5. Interactive Visualizations
 Enhancement: Add charts to show predicted price trends, comparisons, and
feature impact.
 Benefit: Improves user understanding and engagement with visual data.

6. Mobile-Friendly Interface
 Enhancement: Make the Django frontend responsive or build a separate mobile
app.
 Benefit: Expands accessibility for mobile users and realtors on the go.

7. Geospatial Data Usage


 Enhancement: Use GIS (Geographic Information Systems) for mapping houses
and nearby facilities (schools, hospitals).
 Benefit: Adds richer context to predictions and supports smarter decision-making.

8. User Feedback Loop


 Enhancement: Allow users to rate prediction accuracy or provide actual prices
after sale.
 Benefit: Enables continual learning and model refinement based on real outcomes.

9. Multiple Property Types


 Enhancement: Support predictions for apartments, villas, commercial spaces, etc.
 Benefit: Broadens application scope for different property investors and users.

10. Deployment on Cloud


 Enhancement: Host the app on platforms like Heroku, AWS, or Azure.
 Benefit: Ensures scalability, accessibility, and better performance.
References
Academic & Technical References
1. Géron, A. (2019). Hands-On Machine Learning with Scikit-Learn, Keras, and
TensorFlow. O'Reilly Media.
2. Raschka, S., & Mirjalili, V. (2019). Python Machine Learning. Packt Publishing.
3. Pedregosa, F., et al. (2011). Scikit-learn: Machine Learning in Python. Journal of
Machine Learning Research, 12, 2825–2830.
4. Zhang, D., & Zhou, L. (2004). Discovering golden nuggets: Data mining in financial
application. IEEE Transactions on Systems.
5. James, G., et al. (2013). An Introduction to Statistical Learning. Springer.
6. Bishop, C. M. (2006). Pattern Recognition and Machine Learning. Springer.
7. Liaw, A., & Wiener, M. (2002). Classification and Regression by randomForest. R
News, 2(3), 18–22.
8. Breiman, L. (2001). Random forests. Machine learning, 45(1), 5-32.
9. Zou, H., & Hastie, T. (2005). Regularization and variable selection via the elastic net.
Journal of the Royal Statistical Society.
10. Taylor, J. W. (2003). Short-term electricity demand forecasting using double
seasonal exponential smoothing. Journal of the Operational Research Society.
Online Documentation & Official Sources
11. Django Documentation – https://docs.djangoproject.com/
12. Scikit-learn Documentation – https://scikit-learn.org/stable/
13. Pandas Documentation – https://pandas.pydata.org/
14. Numpy Documentation – https://numpy.org/doc/
15. Matplotlib & Seaborn – https://matplotlib.org/ | https://seaborn.pydata.org/
16. Heroku Deployment Docs – https://devcenter.heroku.com/categories/deployment
17. Joblib for Model Serialization – https://joblib.readthedocs.io/
18. UCI Machine Learning Repository – https://archive.ics.uci.edu/ml/index.php
19. Kaggle Dataset: House Prices – https://www.kaggle.com/competitions/house-prices-
advanced-regression-techniques
20. Real Python: Django for Beginners – https://realpython.com/tutorials/django/

You might also like