Skip to content

fwaskito/attrition-prediction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Attrition Prediction

GitHub Created At DOI

Employee attrition prediction system is a ML-based decision support system (DSS). The system use the k-nn method, a supervised learning classifier, to predict whether a future employee will leave the company or not based on employee data in the database.

The raw data used to provide employee data and design the database schema is the IBM attrition dataset. This dataset was analyzed and pre-processed before being imported into the system database.

Tech Used

Most Vital

  • Venv — Lightweight Python virtual environment
  • Flask — Flexible web framework for Python
  • Bootstrap — Front-end development framework
  • PostgreSQL — Relational database

Dependencies

Static Badge Badge Static Badge Static Badge Static Badge

Installation

1. Install Dependency

Create a local Python virtual environment in the project's root directory, then install the dependencies using the pip command.

pip install -r requirements.txt

Tip

Optionally, we can use environment management tools for Python such as Miniconda or Virtualenvwrapper. Using the same commands as above, install the dependencies in a centralized environment instead of a local one, for a more organized way of working.

2. Import Database

Create a new database. Then import this system database into your newly created database.

CREATE DATABASE new_database;

Basic psql import command with implicit user (postgres)

psql new_database < attrition_prediction.bak

or with specific user.

psql -U user_name -W -d new_database -f attrition_prediction.bak

Note

Location of database backup files in the project: app/api/models/backup/*.

Tip

If using a remote database, replace database_name with database_URL instead.

3. Add New User to Database

INSERT INTO sys_user
VALUES ('US2', 'Your Name', 'admin', 'your_username', 'your_password');

4. Set Necessary Environment Variables

There are several environment variables that are used as configuration when the application runs. These variables are listed below:

Variabel Description
FLASK_APP flask run-script location
SECRET_KEY key to sign session cookie
POSTGRES_HOST database host name
POSTGRES_DATABASE database name
POSTGRES_USER user used to access database
POSTGRES_PASSWORD user authentication password

Set environment variables on Linux using Bash.

export FLASK_APP="app/app.py"
export SECRET_KEY="create your own key"
export POSTGRES_HOST="your_host"
export POSTGRES_DATABASE="your_database_name"
export POSTGRES_USER="your_name"
export POSTGRES_PASSWORD="your_password"

Set environment variables on Windows using PowerShell.

$Env:FLASK_APP="app/app.py"
$Env:SECRET_KEY="create your own key"
$Env:POSTGRES_HOST="your_host"
$Env:POSTGRES_DATABASE="your_database_name"
$Env:POSTGRES_USER="your_name"
$Env:POSTGRES_PASSWORD="your_password"

Variables as above are temporary. So we need to re-set them every time we change sessions (e.g., reopen the shell).

Tip

Optionally, we can create aliases for several commands in Bash or PowerShell to increase the efficiency of repeated use. So, we can set all variables with a simple command (e.g., exportenv).

Usage

Go to the demo to try out this system.

Use this identity to login.

  • Username: fwaskito
  • Password: fwaskito123

License

The source code of this system is under the BSD 2-Clause license.