You can use the following commands to set up a virtual environment and install the necessary packages:
# Create a virtual environment (optional but recommended)
python -m venv venv
# Activate the virtual environment
# On Windows (Command Prompt)
venv\Scripts\activate
# On Windows (PowerShell)
venv\Scripts\Activate.ps1
# On macOS/Linux
source venv/bin/activate
# Install dependencies from requirements.txt
pip install -r requirements.txtTo exit (deactivate) the virtual environment, simply run:
deactivateTest code for SARIMA model
The SARIMA (Seasonal Autoregressive Integrated Moving Average) model is a statistical model used for forecasting time series data, and it can decompose observed values into components such as trend, seasonality, and white noise (residuals). Here's a general logic for how the SARIMA model separates observed values:
-
Differencing: The first step in the SARIMA model is differencing the data. This is done to reduce the trend component. The order of differencing is adjusted to ensure data stationarity. If the trend is already a stationary process, differencing may not be necessary.
-
Seasonal Identification: If there is seasonality in the data, the SARIMA model needs to capture it. Identify the seasonal pattern (e.g., yearly, quarterly, monthly), and set the seasonal orders (P, D, Q) accordingly.
-
Model Specification: The SARIMA model is defined by combining elements of AR (AutoRegressive), I (Integrated), MA (Moving Average), and seasonal components. Choose the appropriate orders for AR (p), I (d), MA (q), and seasonal AR (P), seasonal I (D), seasonal MA (Q). This is typically done using plots of autocorrelation and partial autocorrelation functions of the data.
-
Model Estimation: Estimate the parameters of the selected model. This is done using statistical methods such as maximum likelihood estimation.
-
Model Diagnosis: Examine the residuals of the estimated model and assess the goodness of fit. Residuals should ideally behave like white noise. Model diagnosis involves plotting the autocorrelation and partial autocorrelation functions of the residuals, checking for normality of the residuals, and other diagnostic checks.
-
Forecasting: Finally, use the SARIMA model to predict future values. Utilize the model parameters to make forecasts that account for trends, seasonality, and residuals.
Test code for state-space model
In a state-space model, there are two variables: the state and the observed value. The observed value at time
The equation concerning the state variable
Test code for Prophet model In Prophet, time series data is conceptualized as having the following components:
Furthermore, time series data is modeled as the sum of these components, and it is constructed with the following formula:
Test code for NeuralProphet model. NeuralProphet is a library released by Facebook, which is a time series data forecasting model based on the combination of Prophet and AR-Net, a self-regressive neural network model.