Code Monkey home page Code Monkey logo

api-deployment-6's Introduction

A Flask-API for a Prediction Model: Belgium Real Estate Prices

This repository showcases a Flask application that creates predictions from a scikit-learn model for the real estates in Belgium. Once the Flask app is run, the presaved model returns the predicted price based on given features. If the model is not found, it will first train the given data, save it as a model, and then give a prediction.

The model is deployed to Heroku which then will be used by web-developers to embed it in their websites.

Project Division:

3 main components of this project:

  • model.py : This file contains a class that handles cleaning the initial dataset, training a machine learning model, and saving it with joblib.
  • cleaning_data.py : This file preprocess the user input, makes sure that the user give the correct data type and filled in the required features in order to predict the price.
  • app.py : This file has the Flask API, once its run, it will receive the user input as a json file, convert it to dataframe, and fit it to the presaved model and return a prediction price. GET methods that were defined as a route will return the expected inputs and data types from the user.

Dependencies

  • Flask
  • Scikit-learn
  • Pandas
  • Numpy
pip install -r requirements.txt

Running API

To run the app, open your terminal in the same directory as your app.py script and run this command.

pip install -r requirements.txt

Endpoints

1. / (GET)
Returns a text : Alive!!

2. /predict (GET)
Returns an explanation of expected column names and valid enteries for prediction to work. Here's a sample input:

{
        "Living area": {'type': int,'optional':False,'default': []},
        "Bedroom": {'type': int, 'optional': False, 'default': []}, 
        "Province": {
            'type': str,
            'optional': False,
            'default': [
                'Brussels', 'Oost-vlaanderen', 'Vlaams-brabant', 'Luik', 'Namen',
                'Luxemburg', 'West-vlaanderen', 'Antwerpen', 'Henegouwen',
                'Waals-brabant', 'Limburg']}, 
        "Property Type": {'type': str, 'optional': False, 'default': ['Apartment','House']},
        "Property Subtype": {
            'type': str,
            'optional': True,
            'default': [
                'Apartment', 'Town-house', 'House', 'Villa', 'Penthouse',
                'Mansion', 'Studio', 'Exceptional property', 'Kot', 'Duplex',
                'Triplex', 'Ground floor', 'Bungalow', 'Loft', 'Chalet',
                'Service flat', 'Castle', 'Farmhouse', 'Country house',
                'Manor house', 'Other properties']
            },
        "Surface of the plot": {'type': int, 'optional': True, 'default': []},
        "HasGarden": {'type': str, 'optional': True, 'default': ['Yes','No']},
        "Garden surface": {'type': int, 'optional': True, 'default': []},
        "Kitchen Type": {
            'type': str,
            'optional': True,
            'default': ['Equipped', 'Semi-equipped', 'Not installed']},
        "Swimming pool": {'type': str, 'optional': True, 'default': ['Yes','No']},
        "Furnished": {'type': str, 'optional': True, 'default': ['Yes','No']},
        "HasFireplace": {'type': str, 'optional': True, 'default': ['Yes','No']},
        "HasTerrace": {'type': str, 'optional': True, 'default': ['Yes','No']},
        "Terrace surface": {'type': int, 'optional': True, 'default': []},
        "Number of frontages": {'type': int, 'optional': True, 'default': []},
        "Building condition": {'type': str, 'optional': True, 'default': ['As new','Good','To renovate']}
}

3. /predict (POST)
Returns an array of prediction based on given JSON objects representing the independent variables. Here's a sample input:

[

{ "Living area": 100, "Bedroom" :3, "Province" : "Brussels", "Property Type" :"Apartment", "HasGarden":"No"  }

] 

Sample output:

{ "Prediction Price": [ 326.41892486583856 ] }

api-deployment-6's People

Contributors

c-morey 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.