# egemenozen1/pytorch-forecasting-tft architecture

> Architecture diagram of the GitHub repository egemenozen1/pytorch-forecasting-tft, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/egemenozen1/pytorch-forecasting-tft
- Repository: https://github.com/egemenozen1/pytorch-forecasting-tft

## Overview

##### Main Components
- Data Layer – Represent the raw dataset (data/AirQualityUCI.csv and .xlsx) as the data source. Include preprocessing steps (missing value handling, feature scaling, and train–test splitting) as a subcomponent.
- Experimentation & Notebooks – Represent the notebooks folder where experiments, data exploration, and analysis are executed. Note that there is extensive use of Jupyter notebooks for analysis and logging (with several lightning_logs directories to manage different model training versions).
- Model Training / PyTorch Lightning – Show the use of PyTorch Lightning for orchestrating model training. This is evident from the lightning logs in both the notebooks and src directories. Distinguish between the training pipeline (data feeding, model iteration, logging checkpoints, and hyperparameter tuning) and the core model, which in this case is the TFT.
- Inference & Evaluation Module – Illustrate how model inference is performed using a pre-trained TFT model (the saved weights like tft_final_model.pth are noted in the model_results folder). Include evaluation metrics such as MAE, MSE, RMSE along with visualizations (plots like scatter and histogram provided in the README).
- Source Code – Indicate the python scripts located in the src directory for setting up the environment and running analysis. These scripts encapsulate business logic for training and evaluating the model.

##### Relationships & Data Flow
- Data Flow: Begin with the data ingestion from the “data” folder → Preprocessing steps → input pipeline feeding experiments in the notebooks and scripts.
- Training Flow: Preprocessed data is then piped into the PyTorch Lightning model training workflow, which uses the TFT model architecture. The training process utilizes logging checkpoints and versioning (as evidenced by multiple “version_x” directories).
- Result Flow: After training, the results (predictions, error metrics, and visualizations) are generated. They are stored in notebooks/model_results, with the final evaluations feeding back into assessments for future improvements.
- Feedback Loop: Optionally, illustrate areas where planned improvements (hyperparameter tuning, additional feature engineering) feed back into the data preprocessing and model training iterations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        D1["AirQualityUCI.csv"]:::data
        D2["AirQualityUCI.xlsx"]:::data
    end

    %% Preprocessing Layer
    subgraph "Preprocessing"
        P["Preprocessing Steps (MissingValueHandling,FeatureScaling,Train-TestSplit)"]:::process
    end

    %% Experimentation & Notebooks
    subgraph "Experimentation & Notebooks"
        NB1["JupyterNotebooks(analysis.ipynb)"]:::exp
        NB2["LightningLogs(Notebooks)"]:::exp
    end

    %% Source Code
    subgraph "Source Code"
        SC["BusinessLogicScripts(SettingEnviroment.py,analysis.py)"]:::src
    end

    %% Model Training / PyTorch Lightning
    subgraph "Model Training / PyTorchLightning"
        MT1["TrainingPipeline(DataFeeding,ModelIteration,HyperparameterTuning)"]:::train
        MT2["LightningLogs(Src)"]:::train
        MT3["TFTModel(CoreModel)"]:::train
    end

    %% Inference & Evaluation Module
    subgraph "Inference & Evaluation"
        IE1["Inference&Evaluation(PerformanceMetrics,Visualizations)"]:::eval
        IE2["ModelResults(tft_final_model.pth)"]:::eval
    end

    %% Future Enhancements
    subgraph "Future Enhancements"
        FE["FutureEnhancements(HyperparameterTuning,FeatureEngineering)"]:::future
    end

    %% Data Flow Connections
    D1 --> P
    D2 --> P
    P --> NB1
    P --> MT1
    SC --> MT1
    NB1 --> NB2

    %% Training Flow Connections
    MT1 --> MT2
    MT1 --> MT3
    MT2 --> MT3

    %% Result Flow Connections
    MT3 --> IE1
    MT3 --> IE2

    %% Feedback Loop
    IE2 --> FE
    FE --> P

    %% Click Events
    click D1 "https://github.com/egemenozen1/pytorch-forecasting-tft/blob/master/data/AirQualityUCI.csv"
    click D2 "https://github.com/egemenozen1/pytorch-forecasting-tft/blob/master/data/AirQualityUCI.xlsx"
    click NB1 "https://github.com/egemenozen1/pytorch-forecasting-tft/blob/master/notebooks/analysis.ipynb"
    click NB2 "https://github.com/egemenozen1/pytorch-forecasting-tft/tree/master/notebooks/lightning_logs/"
    click MT2 "https://github.com/egemenozen1/pytorch-forecasting-tft/tree/master/src/lightning_logs/"
    click SC "https://github.com/egemenozen1/pytorch-forecasting-tft/tree/master/src/"
    click IE2 "https://github.com/egemenozen1/pytorch-forecasting-tft/tree/master/notebooks/model_results/"

    %% Styles
    classDef data fill:#ffe0f0,stroke:#cc0066,stroke-width:2px;
    classDef process fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef exp fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef train fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef eval fill:#fde2e2,stroke:#a71d2a,stroke-width:2px;
    classDef src fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef future fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
