This project demonstrates the implementation of a Temporal Convolutional Network (TCN), a powerful deep learning architecture for sequence modeling, on a synthetically generated time-series dataset. The primary goal is to showcase the model's ability to learn complex temporal patterns, including trends, seasonality, and noise.
The objective is to build and train a TCN model capable of accurately forecasting future values of a time series. Instead of using a standard real-world dataset, this project intentionally uses synthetic data. This approach allows for a controlled environment to demonstrate the core mechanics and capabilities of the TCN architecture in capturing specific, known patterns like sine waves and linear trends, combined with engineered noise. The goal is to highlight a fundamental understanding of the model's architecture and its application using the Darts library.
The project was executed with a clear, step-by-step methodology to illustrate the forecasting workflow.
-
Synthetic Data Generation: I created a complex time series by combining several distinct components:
- A linear trend to simulate long-term growth.
- A sine wave to represent clear seasonality.
- Gaussian noise to mimic random, unpredictable fluctuations.
- This noise was further modulated by another sine wave to create heteroscedasticity (non-constant variance), a common challenge in real-world data.
-
Data Splitting: The generated series of 400 time steps was split into a training set (70%) and a validation set (30%) to ensure the model could be evaluated on unseen data.
-
Model Implementation (TCN): I implemented the
TCNModelfrom the Darts library. Key architectural choices included:- Input/Output Chunk Length: Set to 30 and 15 respectively, defining the lookback and forecast windows.
- Causal Convolutions: The model uses dilated causal convolutions, which allow its receptive field to grow exponentially, enabling it to learn long-term dependencies efficiently.
- Probabilistic Forecasting: A
GaussianLikelihoodwas used, allowing the model to not only predict a single future value but also to estimate a range of likely outcomes, which is crucial for understanding forecast uncertainty.
-
Training and Prediction: The model was trained for 100 epochs on the training data. Subsequently, it was used to generate a probabilistic forecast over the validation period to visually and metrically assess its performance.
- Primary Library: Darts
- Backend Framework: PyTorch, PyTorch Lightning
- Data Handling: NumPy
The dataset for this project is synthetically generated to create a controlled experimental setup. It consists of 400 data points and is composed of the following layers:
- A linear trend.
- A primary sine wave for seasonality.
- Gaussian noise with non-constant variance.
This composition creates a challenging yet interpretable time series, ideal for demonstrating a model's learning capabilities.
-
Clone the repository:
git clone https://github.com/your-username/your-repository-name.git cd your-repository-name -
Set up a Python environment and install dependencies:
pip install darts torch
-
Run the Jupyter Notebook:
jupyter notebook "TCN for timeseries_random data.ipynb"
The TCN model successfully learned the underlying patterns in the synthetic data. The final prediction plot shows that the model's forecast closely follows the actual trend and seasonality of the validation set. The probabilistic forecast (represented by the confidence interval) effectively captures the data's volatility, demonstrating the model's ability to quantify uncertainty.
1. Synthetic Data Generation:
2. TCN Model Forecast vs. Actuals:
This project was a focused exercise designed to build a deep, foundational understanding of the TCN architecture for time-series forecasting.
- Architectural Insight: By building a TCN from the ground up using the Darts library, I gained practical knowledge of key concepts like causal convolutions, dilated convolutions, and residual blocks, and how they contribute to effective sequence modeling.
- Power of Synthetic Data: Using synthetic data was an intentional choice that proved highly effective for learning. It allowed me to isolate and confirm the model's ability to learn specific patterns without the ambiguity of real-world noise.
- Probabilistic Forecasting: Implementing a
GaussianLikelihoodhighlighted the importance of moving beyond single-point forecasts. Quantifying uncertainty is critical in real-world applications, and this project provided hands-on experience in that area.
💡 Some interactive outputs (e.g., plots, widgets) may not display correctly on GitHub. If so, please view this notebook via nbviewer.org for full rendering.
Email: imehranasgari@gmail.com.
This project is licensed under the Apache 2.0 License – see the LICENSE file for details.