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.
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()
ds | yhat | yhat_lower | yhat_upper | |
---|---|---|---|---|
3265 | 2017-01-15 | 8.199274293717105 | 7.457612848198393 | 8.947326807036642 |
3266 | 2017-01-16 | 8.524244182734018 | 7.795218022141933 | 9.259560519736194 |
3267 | 2017-01-17 | 8.311615210427806 | 7.613774359875597 | 8.980355920426032 |
3268 | 2017-01-18 | 8.144232020907555 | 7.431967630856238 | 8.840424745282913 |
3269 | 2017-01-19 | 8.156091016939348 | 7.3900334168720265 | 8.928114119568646 |
# 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"]]