Skip to main content

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.

Metadata

Release files for og-learn 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for og-learn 1.0.0
File Size Uploaded Provenance
og_learn-1.0.0.tar.gz 47.7 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for og-learn 1.0.0
File Interpreter ABI Platform
og_learn-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 105.0 kB

Release files / og_learn-1.0.0.tar.gz

Download URL og_learn-1.0.0.tar.gz
Size 47.7 kB
Tags Source
SHA-256 checksum
How to use checksums
78c26561ebaecf242b6c681ec3e3176d7f7ab08f0d579863d49d4b368fc382a9
BLAKE2b-256 checksum
How to use checksums
aa20cdd580dd0e0a13e3b7ebb7490b0404dce2e4f47cf57d04338ea2c06c5075
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 12, 2025.

Transparency log

Release files / og_learn-1.0.0-py3-none-any.whl

Download URL og_learn-1.0.0-py3-none-any.whl
Size 57.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b186bce857054d996f1a4d1a3d1ad75a1385394290613995583086f98babde6
BLAKE2b-256 checksum
How to use checksums
552444c3cd7030bc134f60b1c745a09ac166235e9809847cfd9ed0ebd8500402
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 12, 2025.

Transparency log

Security for og-learn 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for og_learn-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 12, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page