Skip to main content

multivariate-probit

Tie out correlated binary outcomes coherently, without assuming independence.

Fit one model per yes/no outcome, any classifier you like, and this package estimates how the outcomes move together. From one fitted model, P(any), P(all), every pattern and every conditional agree with each other: the 2^d pattern probabilities sum to exactly 1.

pip install multivariate-probit            # numpy + scipy only
from multivariate_probit import MultivariateProbit

model = MultivariateProbit(inner="linear", dependence="pairwise").fit(X, Y)  # Y: (n, d) of 0/1

proba = model.predict_proba(X_new)
proba.marginal                          # P(Y_j = 1 | x), shape (n, d)
proba.any()                             # P(at least one outcome)
proba.all([0, 2])                       # P(outcomes 0 and 2 both)
proba.joint([1, 0, 1])                  # P(exactly this pattern)
proba.conditional(2, given={0: 1})      # P(Y_2 = 1 | Y_0 = 1, x)
model.correlation_                      # the fitted correlation matrix Σ, (d, d)

Background and a worked example: quantecarlo.com/multivariate-probit. Using this on a real problem? Tell us in a use-case issue.

You might be looking for this if…

  • You need P(at least one) across several correlated binary labels, and multiplying per-label probabilities gives the wrong answer.
  • Your multilabel or multi-output model treats labels as independent, and you need the joint probability of a label combination.
  • You've used R mvProbit or Stata mvprobit and want multivariate probit in Python, with standard errors from a full-likelihood fit or prediction at scale.
  • You want to combine several fraud or risk model scores into one probability that "any of these happened."
  • You need co-occurrence or label dependence expressed as one correlation matrix, a tetrachoric correlation that conditions on features.
  • You want a Gaussian copula for binary outcomes on top of XGBoost or scikit-learn classifiers.
  • You need a multi-outcome model that a validator can read: per-outcome coefficients plus an explicit correlation matrix (see Explainability).
  • You need P(outcome A | outcome B already happened) from the same model that gives the marginals.

The model

A multivariate probit: each outcome is a threshold on a latent Gaussian score, and the scores are correlated.

Y_j = 1[ η_j(x) + e_j > 0 ],    e ~ N(0, Σ),    j = 1 … d

η_j comes from any per-outcome model. Σ is a correlation matrix; with intercept-only margins, ρ_jk is the classical tetrachoric correlation, and with features it is the tetrachoric correlation conditional on x. Fitting is two-stage Inference Functions for Margins (IFM): each margin is fitted alone and cross-fitted, then Σ is estimated by maximum likelihood with the margins held fixed (docs/ifm.md). For linear margins, fitter="modal" is the alternative: full maximum likelihood, all margins and Σ at once, on a hosted GPU, with standard errors (docs/fiml.md).

Why not write it yourself

It is a short model to write down. These are the places a first version goes wrong; each is handled here and documented.

  • In-sample margins drive every fitted correlation toward +1. An overfit margin is most confident on the rows where the labels co-occur, and stage two reads that as dependence. Margins are cross-fitted by default (cv=5); test_cross_fitting_removes_upward_bias_in_the_correlation pins it. Mechanism.
  • Full-likelihood Σ does not scale with d. Each likelihood call costs n_quad ** (d - 2) bivariate evaluations per row; at d = 4 and 250 rows a joint fit took 2-4 minutes. The pairwise estimator uses only closed-form bivariate integrals and took about 0.07 s on the same data, with the same accuracy (studies/comparators.md).
  • SciPy's multivariate normal CDF is one call per row. Scoring a test set is a Python loop, measured at 3e-3 to 2 s per row, slowest on the near-singular Σ that pairwise fits produce (studies/ghk.md).
  • Near-duplicate labels push ρ to ±1, where Σ is singular. Each ρ is bounded to abs(ρ) ≤ 0.999, and a pairwise Σ is projected onto the nearest valid correlation matrix before any joint query (docs/ifm.md).
  • Pairwise estimates need not form a valid matrix. Three correlations estimated separately can be jointly impossible; the projection repairs that (test_nearest_correlation_repairs_an_incoherent_triple).

Explainability, scoped

  • Linear margins (inner="linear", the default): per-outcome probit coefficients (model.inner_models_[j].coef_, .intercept_) plus an explicit correlation matrix. That is an interpretable joint model end to end.
  • XGBoost, random forest or other flexible margins: the dependence is still explicit and readable in correlation_, but each margin is as much a black box as the classifier inside it. SHAP is the tool for explaining a single black-box model; this package does not make one explainable.
  • Standard errors with fitter="modal" only. The IFM fit gives point estimates (limitations); the full-likelihood fit returns stderr_ and cov_params_ for the coefficients and Σ.

Bring your own model, or use ours

Stage two consumes only each margin's predicted probability, mapped to the latent scale, so the per-outcome model is a black box: anything with predict_proba, or anything with latent(X).

Preset Estimator Install
"linear" (default), "probit" native probit via IRLS —
"xgboost", "xgb" XGBClassifier, tuned for calibration [xgboost]
"rf", "random_forest" RandomForestClassifier [sklearn]
MultivariateProbit(inner=XGBClassifier(max_depth=4))       # any sklearn-style classifier
MultivariateProbit(inner=["linear", "xgboost", "rf"])      # one per outcome
register_inner("mine", make_my_model)                      # your own preset

The API is scikit-learn style (fit, predict, predict_proba, score, get_params, set_params) without requiring scikit-learn, and works with clone, Pipeline and cross_val_score. Contract and calibration check: docs/api.md.

Scale

Scoring a fitted model, P(Y = y | x), is a d-dimensional integral per row. The backend is chosen with evaluator=:

evaluator Speed Accuracy Runs
"quadrature" (default) 8e-5 s per row at d = 3, 0.12 s at d = 6, impractical past 7 about 1e-5, deterministic locally
"scipy" 3e-3 to 2 s per row, any d reference grade, randomised locally
"orthant" 2e-5 to 9e-5 s per row, d = 4 to 20 median error ≤ 0.007, deterministic locally, compiled, keyed above d = 3

Speed, with a small accuracy trade-off: "orthant" is two to five orders of magnitude faster than SciPy, at roughly the accuracy of 100-draw GHK simulation (studies/ghk.md). It ships for CPython 3.11 and 3.12 on x86-64 Linux (pip install multivariate-probit[orthant]); without a key it runs d ≤ 3 at resolution="low". The key is read from $ORTHANT_KEY or ~/.orthant/key at import, or passed in code with from multivariate_probit import orthant; orthant.activate(key) (on Spark, call it inside the function the workers run). Key: quantecarlo.com/orthant_key.

Benchmarks against other tools: docs/benchmarks.md.

Where your data goes

Nowhere, by default. Fitting and every evaluator run on your machine; the package makes no network calls, and the "orthant" key is checked offline.

The exception is opt-in: fitter="modal" uploads X, Y and sample_weight to a GPU service for the full-likelihood fit and gets parameters back. Everything after fit runs locally.

The one hosted path is a separate package you call yourself: quantecarlo.orthant_cdf, a GPU service for test sets too large for one machine. It sends the (N, d) array of latent scores (model.transform(X)), the correlation matrix and, for a pattern query, that pattern as a sign vector. It never receives X. To keep everything local, don't install or call quantecarlo.

When to use what

Tool The right choice when
scikit-learn MultiOutputClassifier Only per-label probabilities matter, never combinations.
scikit-learn ClassifierChain (or an ensemble of chains) The goal is predicting the exact label set; ensembles of chains had the best subset accuracy at d = 6 in this benchmark.
Label powerset (one class per label combination) Few labels, and every combination you care about is common in the training data.
One stacked model on a combined target Only one fixed combination matters and it has enough positives to train on.
statsmodels Probit, one per outcome You need classical inference on each outcome's coefficients and only marginal probabilities.
pybhatlib Discrete-choice econometrics (multinomial probit, multivariate ordered response probit) by maximum likelihood with Bhat's analytic MVNCD approximation and analytic gradients.
R mvProbit, Stata mvprobit A classical full-likelihood multivariate probit with linear indices and small d, inside R or Stata.
multivariate-probit Coherent joint queries (any, all, pattern, conditional) on top of flexible per-outcome models, with scoring that scales to large N.

Use cases

Problems that fit this shape, each with the joint query that answers it and a runnable example on synthetic data:

Documentation

Citing

See CITATION.cff.

Development

pip install -e ".[dev]"
pytest

License

MIT. See LICENSE.

Metadata

Release files for multivariate-probit 0.3.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 multivariate-probit 0.3.2
File Size Uploaded Provenance Actions
multivariate_probit-0.3.2.tar.gz 228.5 kB Without provenance Details for multivariate_probit-0.3.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for multivariate-probit 0.3.2
File Interpreter ABI Platform Actions
multivariate_probit-0.3.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details for multivariate_probit-0.3.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
multivariate_probit-0.3.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details for multivariate_probit-0.3.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Total release size: 3.2 MB

Release files / multivariate_probit-0.3.2.tar.gz

Download URL multivariate_probit-0.3.2.tar.gz
Size 228.5 kB
Tags Source
SHA-256 checksum
How to use checksums
70927a40a80a48e03b57236bcde188db14f2e032ad02d64da3b3fc4d7e86892e
BLAKE2b-256 checksum
How to use checksums
1630a287c5c8f393ed533cd8c9eaeaa721d8d57e59cbaa63920c1c69a056d07b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.9

Release files / multivariate_probit-0.3.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL multivariate_probit-0.3.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.5 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
8ff253d5fe0bdee90e31ded83f5eef1974681da59e710a56aac555c0249e5574
BLAKE2b-256 checksum
How to use checksums
d63de7797bfde19edfdab61cc85dfc2d228694695eff0be90bbb14835a4e300b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.9

Release files / multivariate_probit-0.3.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL multivariate_probit-0.3.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.5 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
4ace7434b4c638d84eeaeec1851d47817c7c26b71ae13b97bfbbd5304b4ea3ca
BLAKE2b-256 checksum
How to use checksums
8da3b9bb512c79392972e0e0a7db6518410303e3cee47f9ba3935e59d440feff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.9

Security for multivariate-probit 0.3.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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