This README provides a step-by-step guide on using Facebook Prophet for time series forecasting. The code snippets provided demonstrate various aspects of the Prophet library, such as data loading, model instantiation, training, prediction, visualization, cross-validation, and performance evaluation.
Before using Prophet, ensure that you have Python installed on your system. You can install Prophet and its dependencies using the following commands:
pip install prophet
pip install pystan
df = pd.read_csv('example_wp_log_peyton_manning.csv')
df.head(10)
df.tail(10)
df.shape
df.info()
df.describe()
model = Prophet()
model.fit(df)
future = model.make_future_dataframe(periods=365)
future.tail(5)
future = model.predict(future)
future.head(5)
future[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail(3)
figure_1 = model.plot(future)
figure_2 = model.plot_components(future)
from prophet.diagnostics import cross_validation
cv = cross_validation(model, initial='730 days', period='180 days', horizon='365 days')
cv.head(5)
from prophet.diagnostics import performance_metrics
pm = performance_metrics(cv)
pm.head(5)
from prophet.plot import plot_cross_validation_metric
figure_3 = plot_cross_validation_metric(cv, metric='smape')
For detailed information on hyperparameter tuning in Prophet, refer to the official Prophet documentation. The documentation covers topics such as choosing the number of Fourier terms, adjusting trend flexibility, modifying seasonality prior scale, and diagnosing overfitting and underfitting.
By following the steps outlined in this README and referring to the official documentation, you can effectively utilize Facebook Prophet for time series forecasting and optimize your model's performance for your specific dataset.