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
mvProbitor Statamvprobitand 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_correlationpins 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 returnsstderr_andcov_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.
With a key, orthant.cdf_grad also returns the gradient of P with respect to the limits and
the covariance, at about 1.5x the cost of cdf, for chance-constrained optimisation
(docs/api.md).
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:
- Fusing fraud and identity vendor scores:
.any(), posterior over fraud types - Claims fast-track eligibility: P(no SIU ∧ no attorney ∧ no total loss)
- HCC codes with hierarchies and interactions:
.joint()over code patterns - Content moderation and ad integrity: P(any policy violation)
- Cyber: phishing and exploited vulnerabilities:
.all(),.any() - Property imagery attributes: roof, pool, solar
Documentation
- docs/ifm.md: the estimation algorithm, and why IFM
- docs/fiml.md: the full-likelihood GPU fit (
fitter="modal"), with standard errors - docs/api.md: parameters, evaluators, the inner-model contract
- docs/implementation.md: what is hand-rolled, numerical accuracy
- docs/limitations.md: known gaps
- docs/benchmarks.md: comparison against other tools
- docs/studies/: every measurement behind the claims above
Citing
See CITATION.cff.
Development
pip install -e ".[dev]"
pytest
License
MIT. See LICENSE.
Metadata
Release files for multivariate-probit 0.3.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| multivariate_probit-0.3.7.tar.gz | 232.0 kB | Without provenance | Details for multivariate_probit-0.3.7.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| multivariate_probit-0.3.7-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.7-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| multivariate_probit-0.3.7-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.7-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
Total release size: 4.9 MB
Release files / multivariate_probit-0.3.7.tar.gz
| Download URL | multivariate_probit-0.3.7.tar.gz |
|---|---|
| Size | 232.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6023335223531d27562ec1fad6be62ac5e81755eb9983f6261e4798d02d96ca9
|
|
BLAKE2b-256 checksum How to use checksums |
c69d0ff298c09ae01f6fd7a71b745cf2f987cb91c268da95765e95cd1387f483
|
| 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.7-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | multivariate_probit-0.3.7-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 2.4 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
8028694eedc851c5262335b92e966dc4082815489e56c4c619c7b740ca25576f
|
|
BLAKE2b-256 checksum How to use checksums |
7b71652fa556b5d7e56a622ee2288276f44df3822bba0b8707824a04e34069c5
|
| 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.7-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | multivariate_probit-0.3.7-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 2.4 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
3860757c08626705a63325f6cf4c3a9ede7dac55a41e83f9b2bb600089aca5ed
|
|
BLAKE2b-256 checksum How to use checksums |
90f4bf641a7402de317a347b0e69271607064abe00e820cc16d0adcc3a28e97b
|
| 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.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.
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.