Skip to main content

OrdBoost

PyPI Version PyPI Python Versions License tests Docs

Table of content

  1. Overview
    1. Key features
  2. Installation
  3. Quickstart examples
    1. OrdBoostClassifier
    2. OrdBoostRegressor
  4. Acknowledgements

Overview

ordboost is a Python library providing ordinal-binning gradient boosting models for discrete and continuous targets with full scikit-learn compatibility.

By framing continuous regression as a dynamic ordinal binning problem, ordboost generates full, non-parametric probabilistic distributions without forcing strict Gaussian or parametric assumptions on target data.

Key Features

  • Scikit-Learn API Compatibility: Fits seamlessly into standard ML workflows using fit, predict, and predict_dist.
  • Non-Parametric Probabilistic Output: Obtains complete predictive distribution objects capable of extracting probability mass functions (PMF), cumulative distribution functions (CDF), percentiles (ppf), and dynamic prediction intervals.
  • Flexible Continuous Target Mapping: Maps continuous values to discrete target spaces using configurable binning strategies (QuantileBinMapper, UniformBinMapper, EmpiricalMeanBinMapper, EmpiricalMedianBinMapper, ContinuousBinMapper).
  • Monotonic Ordinal Constraints: Supports constrained ordinal boosting (e.g., isotonic constraints) across sequential boundaries.
  • Probabilistic Evaluation: Evaluates probabilistic predictions directly using CRPS (crps_score), quantile loss (pinball_loss), and their skill scores.
  • Prediction Intervals Measures: Measures the prediction interval coverage (interval_coverage_rate), sharpness (sharpness), and Winkler score (winkler_score).
  • Calibration Diagnostics: Computes marginal calibration (marginal_calibration_curve) and probabilistic calibration (pit_diagnostics).

Installation

Install the latest release from PyPI:

pip install ordboost

Note: It is recommended to install the package inside a virtual environment (venv or conda).

Some of the plotting examples (calibration and bounded-data) additionally need matplotlib. Install it with pip install matplotlib, or install the development extras with pip install -e ".[dev]" from a clone of the repository.


Quickstart Examples

OrdBoostClassifier

import numpy as np
from ordboost import OrdBoostClassifier, crps_score, pinball_loss

# 1. Prepare ordinal target dataset (e.g., discrete ratings 1 to 5)
np.random.seed(42)
X_train = np.random.randn(200, 4)
y_train = np.random.choice([1, 2, 3, 4, 5], size=200)

X_test = np.random.randn(50, 4)
y_test = np.random.choice([1, 2, 3, 4, 5], size=50)

# 2. Fit OrdBoostClassifier
model = OrdBoostClassifier(
    max_iter=50,
    learning_rate=0.05,
    monotonicity="isotonic",
    max_leaf_nodes=15,
    random_state=42,
)
model.fit(X_train, y_train)

# 3. Predict point estimates (mean or median)
y_pred_mean = model.predict(X_test, method="mean")

# 4. Extract discrete probability distribution
dist = model.predict_dist(X_test)
pmf = dist.pmf  # Probability mass function shape: (50, 5)
cdf = dist.cdf  # Cumulative distribution function shape: (50, 5)
y_pred_q90 = dist.ppf(0.90)  # 90th percentile prediction

# 5. Evaluate probabilistic performance
crps = crps_score(y_test, dist)
p_loss = pinball_loss(y_test, y_pred_q90, alpha=0.9)

print(f"Discrete CRPS: {crps:.4f}")
print(f"Pinball Loss (q=0.9): {p_loss:.4f}")

OrdBoostRegressor

import numpy as np

from ordboost.models import OrdBoostRegressor

# 1. Generate synthetic continuous regression data with non-linear skew
rng = np.random.default_rng(42)
X_train = rng.standard_normal((300, 3))
y_train = np.exp(X_train[:, 0] * 0.6) + rng.normal(0.0, 0.5, size=300)

X_test = rng.standard_normal((3, 3))

# 2. Instantiate and fit OrdBoostRegressor using dependency injection
reg = OrdBoostRegressor(
    bin_edges=[0.0, 1.0, 2.5, 5.0, 15.0],
    mapper="quantile",
    mapper_kwargs={"quantiles": (0.10, 0.25, 0.50, 0.75, 0.90)},
    learning_rate=0.05,
    max_iter=50,
    random_state=42,
)
reg.fit(X_train, y_train)

# 3. Generate continuous point predictions
y_pred_mean = reg.predict(X_test, method="mean")
y_pred_median = reg.predict(X_test, method="median")

# 4. Extract continuous predictive distribution object
dist = reg.predict_dist(X_test)

# Evaluate 80% prediction intervals and cumulative probability P(Y <= 3.0)
lower_80, upper_80 = dist.interval(alpha=0.20)
prob_under_3 = dist.cdf(3.0)

# Display predictions for test samples
for i in range(len(X_test)):
    print(f"Sample {i + 1}:")
    print(f"  Predicted Mean:      {y_pred_mean[i]:.2f}")
    print(f"  Predicted Median:    {y_pred_median[i]:.2f}")
    print(f"  80% Interval:        [{lower_80[i]:.2f}, {upper_80[i]:.2f}]")
    print(f"  P(Y <= 3.0):         {prob_under_3[i]:.2%}\n")

Acknowledgements

This package was developed using Gemini 3.6 Thinking and Claude Sonnet 5. The code was reviewed and edited by humans.

Metadata

Release files for ordboost 0.6.2

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

Source distribution (sdist)

Source distribution for ordboost 0.6.2
File Size Uploaded Provenance Actions
ordboost-0.6.2.tar.gz 49.8 kB With provenance Details for ordboost-0.6.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ordboost 0.6.2
File Interpreter ABI Platform Actions
ordboost-0.6.2-py3-none-any.whl Python 3 none any Details for ordboost-0.6.2-py3-none-any.whl

Total release size: 87.1 kB

Release files / ordboost-0.6.2.tar.gz

Download URL ordboost-0.6.2.tar.gz
Size 49.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9eabd7c9be948052bd40abc0f35dbec1bf6984a8644b3e7ad226e1b716206111
BLAKE2b-256 checksum
How to use checksums
566316927c400b25f0b2258fcf306e3b717d38a57612d2bbb5155c3dc1913970
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Release files / ordboost-0.6.2-py3-none-any.whl

Download URL ordboost-0.6.2-py3-none-any.whl
Size 37.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d101dce14a65e459a4241e196e8ea1a96e9c055657c105084b50e83b9795296d
BLAKE2b-256 checksum
How to use checksums
c9e2bbf269053d253658ee9510082816407efc0e28c85324ea7b1ef07944eecd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Security for ordboost 0.6.2

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ordboost-0.6.2.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 Nov 22, 2026.

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.

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