top of page
Untitled

DATA DOUBLE CONFIRM

Modelling COVID-19 cases in Singapore - Part II

Here I make use of the package fbprophet to forecast the number of COVID-19 cases in Singapore using Python. Quoting from the official site on Prophet: Prophet is a procedure for forecasting time series data based on an additive model where non-linear trends are fit with yearly, weekly, and daily seasonality, plus holiday effects. It works best with time series that have strong seasonal effects and several seasons of historical data. Prophet is robust to missing data and shifts in the trend, and typically handles outliers well. Prophet is open source software released by Facebook’s Core Data Science team. It is available for download on CRAN and PyPI.

But before I go into the modelling process (which is really simple given how it was developed for ease of use), I will cover how to overcome the multiple errors installing fbprophet. If you're more fortunate than me in installation, then you can scroll to the bottom.

To install the package fbprophet, I need pystan to be installed, so I ran pip install pystan. But I still didn't manage to install fbprophet successfully after installing pystan, and got another error message, error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools. I went on to install Visual Studio and download "Build Tools For Visual Studio" under "Tools for " Visual Studio" (as per advice on this thread), but still didn't manage to get pass this error. Found another thread and tried the solution to use conda install -c conda-forge fbprophet instead and it worked!

So now the next step is to import fbprophet into python/ jupyter notebook. And then I got an error again, ImportError: cannot import name 'easter' from 'holidays'. There were a few suggestions/ solutions on stackoverflow but some didn't work for me. Eg. I tried running from dateutil.easter import easter in the cell before from fbprophet import Prophet but that didn't work. The solution that worked for me was to downgrade holidays version through running pip install holidays==0.9.12.

Now finally I can use Prophet to do some forecasting. Basically there are a few standard lines of code that you can run and get the forecasting results immediately (the process is really hassle-free).

df.columns = ['ds', 'y'] #we need to rename the columns in our dataframe to be ds and y model = Prophet() model.fit(df) future = model.make_future_dataframe(periods=30) forecast = model.predict(future)

plot1 = model.plot(forecast)

By default, the uncertainty interval is set at 80%. You can change it to 95% by indicating model = Prophet(interval_width=0.95). [Source]

Official quick start tutorial can be found here: https://github.com/facebook/prophet/blob/master/notebooks/quick_start.ipynb.

bottom of page