Code Monkey home page Code Monkey logo

housepricemodel's Introduction

House Price Prediction

AIM:

To design a website to train the house price model and to predict the price.

DESIGN STEPS:

Step 1:

Requirement collection.

Step 2:

Creating the layout using HTML and CSS.

Step 3:

Train the model using the given data set

Step 4:

Save the trained model using pickle

Step 5:

Get the input from the user

Step 6:

Load the trained model using pickle

Step 7:

Apply the given data to the model

Step 8:

Display the result

Step 9:

Publish the website in the given URL.

PROGRAM:

HouseModelPrediction.html

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">

    <title>House Price Prediction</title>
  </head>
  <body>
    
        <div class="jumbotron jumbotron-fluid" style="background-color:rgb(212, 33, 93); ">
        
            <div class="container text-center">
            <h1>House Price Prediction</h1>
            <p class="lead">You can use this website to calculate your house price</p>
            </div>
        </div>     
        <div class="container" >                      
            <form action="/HouseModelPrediction/" method="POST">
                {% csrf_token %}
            <div class="form-group row">
                <label for="area" class="col-md-2 col-form-label" style="background-color:rgba(21, 41, 224, 0.479); ">Total Area</label>
                <div class="col-md-10">
                <input type="text" class="form-control" id="area" name="area" placeholder="1500"  value="{{area}}">
                </div>
            </div>            
            <div class="form-group row">
                <label for="bathrooms" class="col-md-2 col-form-label" style="background-color:rgba(38, 31, 172, 0.479); ">Bath Rooms</label>
                <div class="col-md-10">
                <input type="text" class="form-control" id="bathrooms" name="bathrooms" placeholder="2" value="{{bathrooms}}"> 
                </div>
            </div>       
            <div class="form-group row">
                <label for="bhk" class="col-md-2 col-form-label" style="background-color:rgba(56, 22, 209, 0.479); ">Bedroom Hall Kitchen</label>
                <div class="col-md-10">
                <input type="text" class="form-control" id="bhk" name="bhk" placeholder="3" value="{{bhk}}">
                </div>
            </div>      
            <div class="form-group row">
                <label for="location" class="col-md-2 col-form-label" style="background-color:rgba(24, 60, 179, 0.479); ">Location</label>
                <div class="col-md-10">
                <select id="location" name="location" class="col-md-10 form-control">
                    {% for loc in locations %}

                        {% if loc == location %}
                            <option selected value="{{loc}}">{{loc}}</option>
                        {% else %}
                            <option value="{{loc}}">{{loc}}</option>
                        {% endif %}
                    {% endfor %}
                </select>
                </div>
            </div>         
            <div class="form-group row text-center">
                <div class="col-md-12">
                    <button type="submit" class="btn btn-primary">Calculate</button>
                </div>                     
            </div>    
            <div class="form-group row">
                <label for="price" class="col-md-2 col-form-label" style="background-color:rgba(65, 27, 236, 0.479); " >Price(Lakh)</label>
                <div class="col-md-10">
                <input type="text" readonly class="form-control" id="price" placeholder="-" value="{{price}}">
                </div>
            </div>                               
        </form>
        </div> 
              

    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>

    <!-- Option 2: Separate Popper and Bootstrap JS -->
    <!--
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script>
    -->
  </body>
</html>

HouseModelTraining.html

<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
        integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <title>House Price Prediction</title>
</head>

<body>
    <div class="jumbotron jumbotron-fluid" style="background-color:rgba(48, 180, 15, 0.548)">
        <div class="container text-center">
            <h1>Price Model Training</h1>
            <p class="lead">You can use this website to calculate your house price</p>
        </div>
    </div>
    <div class="container">
        <form action="/HouseModelTraining/" method="POST">
            {% csrf_token %}
            <div class="form-group row">
                <label for="samples" class="col-md-2 col-form-label" style="background-color:rgba(233, 25, 25, 0.363);">Total Samples</label>
                <div class="col-md-10">
                <input type="text" readonly class="form-control" id="samples" value="{{samples}}">
                </div>
            </div>
            <div class="form-group row text-center">
                <div class="col-md-12">
                    <button type="submit" class="btn btn-primary">Train</button>
                </div>
            </div>
            <div class="form-group row">
                <label for="score" class="col-md-2 col-form-label" style="background-color:rgba(194, 11, 11, 0.363);">Score</label>
                <div class="col-md-10">
                <input type="text" readonly class="form-control" id="score" value="{{score}}">
                </div>
            </div>
        </form>
    </div>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
        integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
        crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
        integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
        crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
        integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
        crossorigin="anonymous"></script>
</body>

</html>

views.py

from django.shortcuts import render

import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.linear_model import LinearRegression
import pickle

# Create your views here.

def HouseModelTraining(request):
    context={}
    data = pd.read_csv("House_data_preprocessed.csv")
    context["samples"] = data.shape[0]

    if request.method == 'GET':
        context["score"] = "-"
        
    if request.method == 'POST':
        Y = data["price"]
        X = data.drop("price", axis="columns")
        X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2)
        house_model = LinearRegression()
        house_model.fit(X_train, y_train)
        score = house_model.score(X_test, y_test)
        context["score"] = score
        with open('house_model.pickle','wb') as f:
            pickle.dump(house_model,f)

    return render(request, 'housepriceprediction/HouseModelTraining.html', context) 

def HouseModelPrediction(request):
    context={}
    data = pd.read_csv("House_data_preprocessed.csv")
    context['locations'] = data.columns[4:]

    if request.method == 'GET':
        context['area'] = '1500'
        context['bathrooms'] = '2'
        context['bhk'] = '3'
        context['location'] = ''
        context['price'] = '-'

    if request.method == 'POST':
        area = int(request.POST.get('area',0))
        bathrooms = int(request.POST.get('bathrooms',0))
        bhk = int(request.POST.get('bhk',0))
        location = (request.POST.get('location','-'))

        context['area'] = area
        context['bathrooms'] = bathrooms
        context['bhk'] = bhk
        context['location'] = location

        Y = data["price"]
        X = data.drop("price", axis="columns")

        with open('house_model.pickle', 'rb') as f:
            house_model = pickle.load(f)

        loc_index = np.where(X.columns==location)[0][0]

        input = np.zeros(len(X.columns))
        input[0] = area
        input[1] = bathrooms
        input[2] = bhk
        if loc_index >= 0:
            input[loc_index] = 1

        price = house_model.predict([input])


        context['price'] = "{0:.2f}".format(price[0])

    return render(request, 'housepriceprediction/HouseModelPrediction.html', context)

OUTPUT:

output

output

CODE VALIDATION REPORT:

output

output

RESULT:

  Thus a website to train the house price model and to predict the price is designed and is hosted in the URLs http://durgadevi.student.saveetha.in:8000/HouseModelPrediction/,http://durgadevi.student.saveetha.in:8000/HouseModelTraining/ .Html code is validated.

housepricemodel's People

Contributors

obedottoc avatar durga46 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.