Web App For Border Crossing Wait Time Forecast

Web App For Border Crossing Wait Time Forecast – Part 1

Keywords: Facebook Prophet, Web App, Flask, AJAX, API, AWS

About a year ago I built a predictive model for predicting border crossing wait time. There were a lot of feature manipulation and parameter tweaking. Although results were encouraging, I always wanted to simplify the process and also make the model available for public use.

After spending two weekends researching and coding (as I have no prior knowledge of Prophet or Flask), here is the improved workflow:

  1. Retrieve border crossing wait time from Cascade Gateway API
  2. Build predictive model for future crossing using Python + Facebook Prophet
  3. Develop web app REST API using Flask, HTML, CSS, ajax
  4. Deploy web app on AWS
  5. Refresh data and re-build predictive model daily
Web App For Border Crossing Wait Time Forecast

Step 1 to 4 is completed and I will continue working on step 5 to rebuild the model daily using live feed from Cascade Gateway.

Link to web app http://35.164.32.109:5000/

It doe not have a permanent address because it’s a free AWS instance (trying to save my cost on this). Forecast is available for next 7 days. Currently it is fixed for 07/09/2019 to 07/15/2019. It will be dynamic and updated daily when daily model rebuild is deployed.

Dataset

Border crossing wait time data is retrieved from Cascade Gateway data warehouse. It has a well-documented API reference and it’s quite simple to use.

I extracted hourly crossing wait time since 01/01/2014 for Peach Arch (BC-Washington) south cars.

Prophet Model

Prophet is an open source time-series forecast library developed by Facebook. Although it doesn’t offer great flexibility for augmenting features, it’s working quite well for practicality and simplicity. Even someone who doesn’t have much expertise in building predictive models can use it to quickly ensemble some good models.

Out of the package, it allows trend, seasonality, and holiday effect analysis. Graphs below are generated simply by one line code

m.plot_components(forecast)

We can see border crossing wait time yearly/weekly/daily seasonality, and trend over the years. More detailed trending analyses can be found in my early study.

Flask Web App

Flask is a micro web framework and it is popular for building web applications with Python. It is light as it does not require particular libraries to start. It is designed to make getting started quick and easy, with the ability to extend to complex tasks. I never used Flask before but it did not take me long to get my first Flask web app up and running.

I wrote Ajax javascript to allow data form interact with Flask. CSS style code was borrowed from this article and made some changes.

Will continue on AWS deployment and daily model rebuild on next article.

Link to web app http://35.164.32.109:5000/

Happy Machine Learning!