Real-time Loan Approval demo
This application is the adopted Feast Credit Scoring Tutorial to use Redis as online feature store and local files as offline store.
Feast supports Redis and so this demo can be configured to use local Redis instance, Redis Cloud or ACRE.
Preparing Redis
Jump to one of the sections below depending on how you want to use Redis for the demo:
Using ACRE
- Go to Azure portal and provision Azure Cache for Redis:
- Populate basic properties and hit 'Create' (Standard tier should be fine for demo):
-
Wait until Redis is fully provisioned (may take up to 20 mins), then navigate to the resource.
-
Go to 'Advanced settings' and enable non-SSL port:
Note: this is for demo purpose only, never do this in production!
- Go to 'Access keys' and grab the connection string - you will need it later while setting up the app as well as the feature store settings:
- Modify connection string to adjust the port number:
loanapp.redis.cache.windows.net:6379,password=Ze...A=
Make note of this string as you will be using this later on.
Using Redis Cloud
coming soon
Using local Redis
coming soon
Local demo setup
- Create new virtual environment and activate it:
python3 -m venv .venv/loanapp
source .venv/loanapp/bin/activate
- Update
pip
and install project dependencies:
pip install -update pip
pip install wheel
pip install -r requirements.txt
- Edit the creditscore/feature_store.yml file to uncomment the
connection_string
property and populate it with the redis connection string you captured before:
online_store:
type: redis
# for Azure:
connection_string: loanapp.redis.cache.windows.net:6379,password=Ze...A=
- Initialize feast repository:
cd creditscore
feast apply
- Materialize features to Redis:
CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%S")
feast materialize-incremental $CURRENT_TIME
- Return to the main directory and train the model:
cd ..
python run.py
You now have the model ready to be served and the latest features materialized and stored in Redis database. You can try and explore the size of the online store by connecting to redis server using redis-cli
:
❯ redis-cli -h loanapp.redis.cache.windows.net -p 6379 -a Ze...A= dbsize
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
(integer) 57477
Running demo locally
You can run and test the model using either run.py
(CLI) or streamlit_app.py
(Browser). Streamlit is the framework that allows building web data apps in minutes.
- First, you need to configure the connection to Redis for your application by creating a file
.streamlit/secrets.toml
and adding the conection string to there:
mkdir .streamlit
echo "redis_connection_string = \"loanapp.redis.cache.windows.net:6379,password=Ze...UA=\"" > .streamlit/secrets.toml
- Next, run the application using the command below:
streamlit run streamlit_app.py
- In the browser you can play with the loan parameters to see if your loan gets approved or rejected.
Note: the loan application parameters are joined with the applicant's credit history (feature vector) stored in Redis to make an approval decision!
Streamlit hosted demo
Follow the instructions on Streamlit Cloud to deploy a hosted version of this demo.
Also, explore Redis Cloud for a free tier of Redis Enterprise on AWS and GCP.