Skip to main content

Overfit-to-Generalization Framework for Equitable Spatiotemporal Modeling

Project description

og-learn

Overfit-to-Generalization Framework for Equitable Spatiotemporal Modeling

DOI PyPI version License: MIT

Overview

og-learn is a Python library that implements the Overfit-to-Generalization (OG) framework, designed to address local overfitting in spatiotemporal machine learning models. The framework redistributes predictive capacity from data-rich to data-poor regions through a two-stage approach.

The Problem: Local Overfitting

Models trained on non-uniformly distributed observations tend to:

  • Overfit to data-dense regions (achieving high accuracy)
  • Underperform in sparse areas (poor generalization)
  • Show inconsistent optimal hyperparameters across different validation groups

This disparity is often invisible when using conventional global metrics.

The Solution: OG Framework

The OG framework exploits complementary properties of different model architectures:

  1. Stage 1 (Overfit): A high-variance model (e.g., LightGBM) is deliberately overfitted to capture local patterns and generate pseudo-labels.

  2. Stage 2 (Generalization): A low-variance model (e.g., MLP, Transformer) learns from the pseudo-labels with density-aware sampling and noise injection.

Installation

pip install og-learn

Quick Start

from og_learn import OGFramework
from og_learn.models import LightGBMOverfitter, TransformerRegressor

# Initialize the OG framework
og = OGFramework(
    hv_model=LightGBMOverfitter(),  # High-variance model for Stage 1
    lv_model=TransformerRegressor(), # Low-variance model for Stage 2
)

# Fit the model
og.fit(X_train, y_train, coords=coordinates)

# Predict
predictions = og.predict(X_test)

Key Features

  • Density-Aware Sampling: Prioritizes sparse regions and rare covariate patterns
  • Unlimited Synthetic Target Generation: Generates high-fidelity pseudo-labels via spatial perturbation
  • Flexible Model Pairing: Supports various HV/LV model combinations
  • Cross-Validation Strategies: Built-in time-wise, site-wise, region-wise, and spatiotemporal-wise CV

Supported Models

High-Variance (HV) Models

  • LightGBM
  • XGBoost
  • CatBoost

Low-Variance (LV) Models

  • MLP (Multi-Layer Perceptron)
  • Transformer Regressor
  • ResNet

Documentation

📖 Full documentation: https://px39n.github.io/og-learn/

Data

Example datasets are available on Zenodo: https://doi.org/10.5281/zenodo.17915696

Direct download: og-learn.zip

Citation

If you use this package in your research, please cite:

@article{liang2025og,
  title={Countering Local Overfitting for Equitable Spatiotemporal Modeling},
  author={Liang, Zhehao and Castruccio, Stefano and Crippa, Paola},
  journal={},
  year={2025}
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

og_learn-1.0.0.tar.gz (47.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

og_learn-1.0.0-py3-none-any.whl (57.3 kB view details)

Uploaded Python 3

File details

Details for the file og_learn-1.0.0.tar.gz.

File metadata

  • Download URL: og_learn-1.0.0.tar.gz
  • Upload date:
  • Size: 47.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for og_learn-1.0.0.tar.gz
Algorithm Hash digest
SHA256 78c26561ebaecf242b6c681ec3e3176d7f7ab08f0d579863d49d4b368fc382a9
MD5 0673de2c4fbcacef6919194972da07cb
BLAKE2b-256 aa20cdd580dd0e0a13e3b7ebb7490b0404dce2e4f47cf57d04338ea2c06c5075

See more details on using hashes here.

Provenance

The following attestation bundles were made for og_learn-1.0.0.tar.gz:

Publisher: publish.yml on px39n/og-learn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file og_learn-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: og_learn-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 57.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for og_learn-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b186bce857054d996f1a4d1a3d1ad75a1385394290613995583086f98babde6
MD5 ce00f2314f6e0d8de6d4309815a5f0da
BLAKE2b-256 552444c3cd7030bc134f60b1c745a09ac166235e9809847cfd9ed0ebd8500402

See more details on using hashes here.

Provenance

The following attestation bundles were made for og_learn-1.0.0-py3-none-any.whl:

Publisher: publish.yml on px39n/og-learn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page