Skip to content

This project implements a Temporal Convolutional Network (TCN) for time series forecasting. Using synthetic data (including trend, seasonality, and noise), the model’s ability to learn complex patterns and provide probabilistic forecasts is demonstrated with the Darts library.

License

Notifications You must be signed in to change notification settings

imehranasgari/DL_TimeSeries_Transformer_TCN_RandomData

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Time-Series Forecasting with a Temporal Convolutional Network (TCN)

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.


Problem Statement and Goal of Project

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.


Solution Approach

The project was executed with a clear, step-by-step methodology to illustrate the forecasting workflow.

  1. 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.
  2. 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.

  3. Model Implementation (TCN): I implemented the TCNModel from 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 GaussianLikelihood was 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.
  4. 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.


Technologies & Libraries

  • Primary Library: Darts
  • Backend Framework: PyTorch, PyTorch Lightning
  • Data Handling: NumPy

Description about Dataset

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.


Installation & Execution Guide

  1. Clone the repository:

    git clone https://github.com/your-username/your-repository-name.git
    cd your-repository-name
  2. Set up a Python environment and install dependencies:

    pip install darts torch
  3. Run the Jupyter Notebook:

    jupyter notebook "TCN for timeseries_random data.ipynb"

Key Results / Performance

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.


Screenshots / Sample Output

1. Synthetic Data Generation:

2. TCN Model Forecast vs. Actuals:


Additional Learnings / Reflections

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 GaussianLikelihood highlighted 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.

👤 Author

Mehran Asgari


📄 License

This project is licensed under the Apache 2.0 License – see the LICENSE file for details.

About

This project implements a Temporal Convolutional Network (TCN) for time series forecasting. Using synthetic data (including trend, seasonality, and noise), the model’s ability to learn complex patterns and provide probabilistic forecasts is demonstrated with the Darts library.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published