Mauna Loa Forecasting CO2 with prophet

 I took this one!

 This will be a very short project where I'll forecast CO2 emmissions recorded on top of Mauna Loa on the Big Island of Hawai'i using the prophet library in python. While it won't be the most complex trend, I mostly wanted to forecast this data having lived on the Big Island for a handful of years and even walked right up to the lava flow a few times... I couldn't pass up the opportunity. Plus prophet is just so easy to setup and use, even tuning it is fairly straight forward. I'll probably circle back and do a more complicated forecast later on, but for now let's holo holo!

Please find the notebook in my GitHub: https://github.com/sam-tritto/mauna-loa-co2

 The Data

 The for this project is from NOAA and can be found here:  https://gml.noaa.gov/ccgg/trends/data.html

It contains weekly, monthly, yearly CO2 emissions data measured on top of the Mauna Loa volcano, dating all the way back to 1953. I'll use the weekly data set, but it only goes back to 1974, which will be more than sufficient for prophet.

Prophet

If it's your first time workign with prophet, I'd suggest installing it in a virtual environment as the dependencies can be a little tricky to manage. I'm using an anaconda virtual env, so if you'd like to do the same you can follow the docs here:  https://anaconda.org/conda-forge/prophet 

After installation, the only preprocessing requirement you'll need to complete will be to label the dependent variable as "y" and the time independent variables as "ds". Prophet also expects daily data, but you can modify the periods easily after the fact if your data is weekly, monthly, or some other interval... just be sure to format your dates as yyyy-mm-dd. 

Next, instantiate the model, fit , and pass in your df. 

Now you can make a future dataframe for the predicitons to be passed into. Since the data is weekly, we can use the freq parameter, along with specifying the appropriate number of periods. Since we'd like a 10 year forecast interval, and there are 52 weeks in a year, it's 52 * 10. Finally, call the predict function and pass in your future dataframe.

At this point the forecast has been made. We can either inspect the raw data, extract certain dates, or plot the predicitons along with their credible intervals (this is a Bayesian forecast so they're credible and not confidence intervals). And we've got a seriously tight fit, for this increasing but cyclical data. 

To inspect the raw predictions, I like to call tail and transpose the dataframe. We could extract what ever dates we're curious about here. We get all sorts of metadata on the forecast such as the upper and lower bounds of the credible intervals.

And lastly, you can decompose the forecast into it's seasonal elements and more general trend. Since the data was weekly, we only get the yearly seasonality. Had we used daily data, we would have also gotten the weekly seasonality. We can see that the CO2 in the atmosphere gradually rises all spring, peaking in June. 

 That's it! Only 9 lines of code for a seriously powerful forecasting tool. There's so much more to explore with prophet; seasonality, change points, holidays, custom dates, multiplicative trends, and more! Beneath these 9 lines of code lie some powerful Bayesian modeling so it can tackle some really tricky trends, but out of the box it's super sharp and simple to use. 

Get in touch at:       mr.sam.tritto@gmail.com