This repository contains an implementation of time series forecasting using Facebook's Prophet model. FB Prophet is a powerful tool for time series analysis, capable of handling missing data and detecting trends, seasonality, and holidays in the data. It is widely used for forecasting data like sales, stock prices, website traffic, and more.
This project demonstrates the use of the Prophet model for forecasting time series data. Prophet is designed to handle univariate time series data, offering robust performance with easy customization for trend, seasonality, and holidays.
- Trend analysis: Detects linear or non-linear trends in time series data.
- Seasonality modeling: Handles daily, weekly, and yearly seasonality.
- Holiday effects: Incorporates holiday effects to improve forecasting accuracy.
- Missing data handling: Automatically deals with gaps in the time series.
- Easy model tuning: Provides straightforward options to adjust model parameters.
To use this project, you'll need to install the required Python packages. You can do so using the following command:
pip install -r requirements.txt- Python 3.x
- FB Prophet
- Pandas
- Matplotlib
- Clone the repository:
git clone https://github.com/your-username/prophet-time-series-analysis.git
cd prophet-time-series-analysis- Prepare your time series data:
Ensure your data is in a pandas DataFrame format with two columns:
ds: the date column (datetime format)y: the target variable (values to forecast)
- Run the script:
You can execute the Prophet model on your dataset using the provided script:
python forecast.py --data your_data.csv --periods 365The input data must have two key columns:
ds(date): This column represents the time stamps for your time series data.y(value): This column contains the values you want to forecast.
Here’s an example of the structure:
| ds | y |
|---|---|
| 2023-01-01 | 100 |
| 2023-01-02 | 102 |
| 2023-01-03 | 98 |
The Prophet model is trained on your historical data to capture the trend, seasonality, and any holiday effects. The following Python code shows how to fit the model:
from fbprophet import Prophet
import pandas as pd
# Load the data
data = pd.read_csv('your_data.csv')
# Initialize the Prophet model
model = Prophet()
# Fit the model
model.fit(data)
# Make predictions
future = model.make_future_dataframe(periods=365)
forecast = model.predict(future)Once the model is trained, it can generate future forecasts:
# Generate future predictions
future = model.make_future_dataframe(periods=365)
forecast = model.predict(future)
# Visualize the forecast
model.plot(forecast)The output will be a forecast plot with confidence intervals, showing the predicted values over the forecast period. The forecast includes:
- Trend component: Captures long-term growth or decline.
- Seasonal components: Displays recurring patterns based on seasonality (e.g., yearly, weekly).
- Holidays: Shows the impact of holidays on the forecast.