Skip to main content

PyTorch-based regressors with uncertainty quantification and scikit-learn interface

Project description

PyPI - Version Python Tests

UQRegressors

UQRegressors is a Python library for regression models that provide prediction intervals, in addition to point estimates. It is meant for machine learning applications where quantifying uncertainty is important.

It features highly customizable parameters for each model, an easy to use interface with built-in dataset validation, GPU compatibility with a PyTorch backend, validated implementations with comparisons to published results, easy saving and loading of created models, and a wide variety of metrics and visualization tools available to assess model quality.

Please direct any questions or suggestions to the email arjunrs@stanford.edu.


Key Capabilities

  1. Dataset Loading & Validation — Utility functions to clean and validate your input data.
  2. Uncertainty‑Aware Regressors
    • Conformal: CQR, K‑Fold CQR, Ensemble‑based CQR
    • Bayesian: Deep Ensembles, MC Dropout, Gaussian Processes (GP, BBMM GP)
  3. Hyperparameter Tuning — Optuna‑based tuning with support for custom interval‑width objective functions.
  4. Uncertainty Metrics — RMSE, coverage, interval width, interval score, NLL, correlation diagnostics, conditional coverage, RMSCD variants, and more.
  5. Visualization Tools — Calibration curves, prediction-vs-true plots, model comparison bar charts.

Installation

To install the core features of UQRegressors:

pip install uqregressors

UQRegressors requires PyTorch, which you should install according to your setup:

  • CPU only:
    pip install torch torchvision torchaudio
    
  • CUDA GPU (choose the version matching your GPU):
    pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
    
  • For other versions, see PyTorch Install Guide.

Getting Started (More detail in full docs)

from uqregressors.bayesian.dropout import MCDropoutRegressor
from uqregressors.tuning.tuning import tune_hyperparams, interval_width
from uqregressors.plotting.plotting import plot_pred_vs_true

# Define a dataset
X_train = np.linspace(0, 1, 5)
X_test = np.linspace(0, 1, 40)
y_train = np.sin(2 * np.pi * X_train)
y_test = np.sin(2 * np.pi * X_test)

# Train an MC‑Dropout regressor
reg = MCDropoutRegressor(epochs=50, random_seed=42)
reg.fit(X_train, y_train)
mean, lower, upper = reg.predict(X_test)

# Visualize results
plot_pred_vs_true(mean, lower, upper, y_test, show=True, title="MC‑Dropout")

# Hyperparameter tuning example (e.g., tuning CQR)
from uqregressors.conformal.cqr import ConformalQuantileRegressor
cqr = ConformalQuantileRegressor(alpha=0.1, epochs=20, random_seed=42)

opt_cqr, best_score, study = tune_hyperparams(
    regressor=cqr,
    param_space={"tau_lo": lambda t: t.suggest_float("tau_lo", 0.01, 0.1),
                 "tau_hi": lambda t: t.suggest_float("tau_hi", 0.9, 0.99)},
    X=X_train, y=y_train,
    score_fn=interval_width,
    greater_is_better=False,
    n_trials=10,
    n_splits=3
)
mean_t, lo_t, hi_t = opt_cqr.predict(X_test)
plot_pred_vs_true(mean_t, lo_t, hi_t, y_test, show=True, title="Tuned CQR")

Documentation

See the complete API Documentation with complete examples:
https://arjunrs3.github.io/UQRegressors/


Contributing

Contributions, issues, and feature requests are welcome! Please:

  1. Fork the repo
  2. Create a feature branch (git checkout -b my-feature)
  3. Commit your changes and push
  4. Open a Pull Request
  5. Email arjunrs@stanford.edu with any questions

License

MIT License


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

uqregressors-1.0.1.tar.gz (15.0 MB view details)

Uploaded Source

Built Distribution

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

uqregressors-1.0.1-py3-none-any.whl (57.4 kB view details)

Uploaded Python 3

File details

Details for the file uqregressors-1.0.1.tar.gz.

File metadata

  • Download URL: uqregressors-1.0.1.tar.gz
  • Upload date:
  • Size: 15.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.1

File hashes

Hashes for uqregressors-1.0.1.tar.gz
Algorithm Hash digest
SHA256 dadcc91dce0af6b8ff03e9c05b9fd16d4d58ceea991fa2f632ad18f5b493dec1
MD5 f61c6b999e67648d5b93a2d39b1c762f
BLAKE2b-256 e47cd5a2132a50981d308a92618d39ed5cb78dfaff2c9b7a1c4c6e0170b068df

See more details on using hashes here.

File details

Details for the file uqregressors-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: uqregressors-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 57.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.1

File hashes

Hashes for uqregressors-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 556a9907a4d15c2df7e39551d1e690c8656aec172951e0f959156adfdce6772a
MD5 8a4e676c7396b725c8f98c5e6c0d520b
BLAKE2b-256 53310e64d09428bb484682e4757918e8ca4c957da0cd6425d0a353d18ff17d56

See more details on using hashes here.

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