Skip to content

HDmoonSir/MultiModal-TimeSeries-Regression

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MultiModal Time-Series Regression Framework

Python License: MIT

A flexible and extensible PyTorch-based framework for multi-modal regression tasks. This project combines time-series and tabular data to predict a continuous target value, leveraging various deep learning architectures like LSTMs, 1D-CNNs, and Transformers for time-series feature extraction.

Key Features

  • Multi-Modal Architecture: Fuses features from both time-series and tabular data for more accurate predictions.
  • Pluggable Encoders: Easily switch between different time-series encoders (LSTM, 1D-CNN, Transformer) via a configuration file.
  • Configuration-Driven: All experiment parameters, including model architecture and training settings, are managed through a single config.yaml file.
  • Automated Experiment Tracking: Automatically saves model checkpoints, training history, and the exact configuration for each run, ensuring reproducibility.
  • Modular Codebase: A clean and organized structure that separates data processing, model definition, and training logic.
  • End-to-End Scripts: Provides ready-to-use scripts for train, test, and inference.

Project Structure

.
├── data/                   # (Optional) Directory for your datasets
├── experiments/            # Directory to save all experiment results
├── src/
│   ├── config/
│   │   └── config.py       # Configuration dataclasses
│   ├── data/
│   │   ├── dataset.py      # PyTorch Dataset class
│   │   └── preprocessing.py# Data loading and preprocessing logic
│   ├── model/
│   │   ├── regression_dl.py# Multi-modal model definition
│   │   └── trainer.py      # Training and evaluation logic
│   └── utils.py            # Utility functions (e.g., loading experiments)
├── config.yaml             # Main configuration file for experiments
├── inference.py            # Script to run inference on a trained model
├── test.py                 # Script to evaluate a trained model
├── train.py                # Main script to start model training
├── README.md               # This file
└── requirements.txt        # Project dependencies

Installation

  1. Clone the repository:

    git clone <your-repository-url>
    cd <repository-name>
  2. Install the required dependencies:

    pip install -r requirements.txt

Usage

Step 1: Prepare Your Data

  1. Place your dataset (in .pkl format) into a directory (e.g., data/).
  2. Update the path_dataset in config.yaml to point to your file.
  3. Crucially, you must customize src/data/preprocessing.py to correctly load your DataFrame, perform any necessary cleaning or feature engineering, and separate the data into time-series features, tabular features, and the target variable.

Step 2: Configure Your Experiment

Modify config.yaml to define your experiment. Key parameters include:

  • model.model_type: Choose between lstm, cnn, or transformer.
  • model.*: Adjust model-specific hyperparameters.
  • train.num_epochs, train.batch_size, train.learning_rate.
  • data.path_dataset: Path to your data file.

Step 3: Train the Model

Run the training script from the root directory:

python train.py

This will create a new directory in experiments/ (e.g., experiments/20250908_160152_lstm/) containing:

  • best_model.pth: The model checkpoint with the lowest validation loss.
  • last_model.pth: The model checkpoint from the final epoch.
  • training_history.json: A log of training and validation losses.
  • config.yaml: A copy of the configuration used for this run.

Step 4: Evaluate the Model

To evaluate the best model on the held-out test set, run the test.py script with the path to your experiment directory:

python test.py experiments/<your_experiment_name>

This will print the final Mean Squared Error (MSE) on the test data.

Step 5: Run Inference

To make a prediction on a single (dummy) data point, use the inference.py script:

python inference.py experiments/<your_experiment_name>

Customization

  • Adding a New Model: To add a new time-series encoder, simply add the logic to src/model/regression_dl.py and update the model_type options in config.yaml.
  • Data Preprocessing: The core of adapting this framework to your own data is by implementing your custom logic in src/data/preprocessing.py.

License

This project is licensed under the MIT License.

About

MultiModal-TimeSeries-Regression

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages