Environment for Business Analytics

Data driven solutions for business. See Business Analytics for a collection of related articles.

Showcase

Prophet

Import the data and dependencies.

example_wp_log_peyton_manning.csv
import pandas as pd
from fbprophet import Prophet

df = pd.read_csv(
example_wp_log_peyton_manning.csv
)

Fit the model by instantiating a new Prophet object. Predictions are then made on a dataframe with a column ds containing the dates for which a prediction is to be made.

The predict method will assign each row in future a predicted value which it names yhat. If you pass in historical dates, it will provide an in-sample fit. The forecast object here is a new dataframe that includes a column yhat with the forecast, as well as columns for components and uncertainty intervals.

m = Prophet()
m.fit(df)

future = m.make_future_dataframe(periods=365)
forecast = m.predict(future)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
dsyhatyhat_loweryhat_upper
32652017-01-158.1992742937171057.4576128481983938.947326807036642
32662017-01-168.5242441827340187.7952180221419339.259560519736194
32672017-01-178.3116152104278067.6137743598755978.980355920426032
32682017-01-188.1442320209075557.4319676308562388.840424745282913
32692017-01-198.1560910169393487.39003341687202658.928114119568646
5 items
# Plot
fig1 = m.plot(forecast)
fig1

Seaborn

import seaborn as sns; sns.set(color_codes=True)
tips = sns.load_dataset("tips")
ax = sns.regplot(x="total_bill", y="tip", data=tips)
ax.figure

Install Forecasting Tools

Python

Forecasting with Prophet

Create the Prophet environment for this notebook and others to import.

pip install --upgrade fbprophet

Statistical Models

statsmodels provides functions and classes for the estimation and inference of statistical models, conducting statistical tests, and statistical data exploration. It is a compliment to scipy.

pip install statsmodels

Plotting With Seaborn

Seaborn is a popular data visualization library.

pip install seaborn

ML Metrics

Supervised machine learning evaluation metrics. This set of standard mathematical functions can also be used to evaluate forecasts for business. For example, in Forecasting Time Series data with Prophet – Part 4.

pip install ml_metrics

Test

import fbprophet as prophet
import statsmodels as stats
import seaborn as seaborn

print("Prophet version " + prophet.__version__ + "\nStatsModels version " + stats.__version__ + "\nSeaborn version " + seaborn.__version__)

Prophet in R

install.packages('prophet')
library(prophet)
packageDescription("prophet")[["Version"]]