Skip to content
A Flask based web app to predict credit card default. The prediction model is developed in python and is based on four regression models: logistic regression model decision tree model Random Forest model Naive Bayes model. The web app is deployed in AWS Elastic Beanstalks.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Credit Card Default Predicting Model

We are using the consumer data provided by UCI Engineering Department to create a credit card default prediction model. The population is over 30,000.There are 24 variables, including age, sex, education and etc. We use the dataset to train 4 regression models and predict if a new customer would default or not.

last updated

01-21-2019 version 0.1

  • flask based web framework


the Presentation Mode Wesbite Preview

Project folder structure


  • static
    • css
    • js
    • img
    • json
    • scss
    • lib
    • node_modules
    • vendor
    • favicon.ico
  • templates
    • index.html (main page)
    • sides_deck.html
    • visuals.html (visualization html to show additional charts)
  • env.example (an example to set up environment to connect to AWS mySQL DB)
  • (main python file)
  • (core prediction model)
  • (run this file to set up a local or remote data table in MySQL database)
  • requirements.txt: list out all necessary libraries/dependencies for the project

Framework and Libraries

  • Core machine learning library: sklearn
  • Python libraries: Pandas, collections, pymysql
  • HTML: Bootstrap
  • JavaScript libraries: jQuery, reveal.js, d3.js, plotly.js
  • Web framework: Flask

Server Environment

Flask Framework

Flask is a micro web frmework written in Python. Unlike a full-blown web framework like Ruby on Rails (for Ruby) or Djano for Python, Flask does not require speicfic additional tools or libraries. It does not have any database abstract layer. or You can click here for more information about the basic Flask Framework

To run a flask web application, we only need a file. Here is the code in the

from flask import Flask
@app.route ("/")
def homepage()
    return "It actually works!"

Amazon Elastic Beanstalk

We used Elastic Beanstalk to deploy our codes without worrying about the infrastructure. The Elastic Beanstalk environment will automatically set up the EC2 instance, VPC, and handle loan blancing, scaling and etc. You can find more information at Amazon Web Service Elastic Beanstalk webiste's welcome page[]


1. How to run the code on your local computer

Make sure that you have the python 3 or above installed on your laptop. Your laptop could be either a PC or Mac.

  • create a virtual environment (optional). let's say the virtual environment's name is "creditcardproject". virtualenv creditcardproject (optional)
  • activate the virtualevn source creditcardproject/bin/activate (optional)
  • clone the github repository
  • on the terminal (Mac OS), navigate to the current project folder. it should look like xxx-MacBook-Pro:ML_CreditCardDefaultPrediction:(username)$:.
  • install libraries pip install -r requirements.txt
  • create a mysql database locally or remotely.
  • make a copy of .env.example rename it to .env.
  • modify the parameters in the .env file based on the database configuration.
  • create the data table in Mysql DB by typing in the terminal python
  • create mysql table using create_mysql_table.sql
  • the data is located at static/csv/cleaned_creditcard.csv
  • after connecting the database, using the database varibales from the real .env setup (Slack channel fpg4 group)
  • run the command on a terminal flask run or python
  • visit the
  • visit the site in the presentation mode at:

2. Deployment to Elastic Beanstalk

Here are the steps

  • clone the github repository
  • navigate the current folder,make a compressed file of all source files. An example is
  • Create and AWS account and login in the AWS Elastic Beanstalk website.
  • create a Elastic Beanstalk environment.
  • upload the compressed source file in the newly created environment.

Regression Models

We are using the data from UCI Engineering Department to create a credit card default prediction model. There are 24 variables in our regression models. We use combined of 4 regression models:

  • Logistic Regression Model
  • Decision Tree model
  • Random Forest Model
  • Naive Bayees Model

Next Steps

Improve the prediction model by implying Netural Network models. Adjust parameters to improve the accuracy upgrade from Flask to Django


  • Stephen Wang
  • and contributors
    • Abula
    • Shanakay
    • Farai
    • Alexandra

Copyright and License

Code released under the MIT License

Special Thank you to Everett Griffiths for inspiration.

You can’t perform that action at this time.