DCMBench
Evaluate discrete choice models of any class on a common footing.
DCMBench takes a fitted model's choice probabilities and computes the rest itself, the same way for every model:
- goodness of fit;
- out-of-sample prediction under respondent-grouped cross-validation;
- elasticities;
- value of time (VOT) distributions;
- policy scenarios and diversion;
- behavioural regularity checks.
A multinomial logit estimated in Biogeme, a mixed logit in PyTorch, a TasteNet, a latent class model, RUMBoost and a random forest can therefore be compared side by side, on the same data, folds and definitions.
pip install dcmbench # core: data, evaluation, reporting, scikit-learn models
pip install "dcmbench[biogeme]" # + Biogeme engine
pip install "dcmbench[torch]" # + PyTorch engines (spec models, any nn.Module)
pip install "dcmbench[all]" # everything
Requires Python ≥ 3.12.
Quick start
import dcmbench.data
from dcmbench.engines.torch import TorchEstimator
from dcmbench.evaluation import CrossValidation, compare
from dcmbench.specs import load_spec
dataset = dcmbench.data.load("swissmetro").prepare("benchmark")
mnl = load_spec({
"spec_version": 2, "name": "swissmetro_mnl", "model": "MNL",
"alternatives": ["train", "sm", "car"],
"parameters": {"ASC_TRAIN": {"start": 0}, "ASC_CAR": {"start": 0}, "B_TIME": {"start": 0}, "B_COST": {"start": 0}},
"utilities": {
"train": "ASC_TRAIN + B_TIME * TRAIN_TT / 100 + B_COST * TRAIN_CO * (GA == 0) / 100",
"sm": "B_TIME * SM_TT / 100 + B_COST * SM_CO * (GA == 0) / 100",
"car": "ASC_CAR + B_TIME * CAR_TT / 100 + B_COST * CAR_CO / 100",
},
})
comparison = compare({"MNL": TorchEstimator(mnl, dataset.problem)}, dataset, protocol=CrossValidation(n_splits=5))
print(comparison.table()[["fit_ll", "oos_avg_ll", "oos_macro_f1", "vot_median[car]"]])
comparison.save("results/") # a specification card per model (JSON + Markdown) and the comparison table
Add more models to the dictionary (any engine, any class) and they are evaluated on identical folds.
What you get for every model
| Dimension | What DCMBench computes |
|---|---|
| Fit | Log-likelihood, ρ², ρ̄² (per observation for panel models, so classes are comparable) |
| Prediction | Holdout, k-fold cross-validation grouped by respondent, or bootstrap: log-likelihood, accuracy, macro F1 / recall, Brier score |
| Elasticities | Point elasticities (own and cross) of time and cost |
| Value of time | Route A from the model's marginal utilities (population draws or individual posteriors); Route B from probability derivatives, for models without utilities. Every result says which route was used |
| Policy | Scenarios (e.g. car cost × 1.5): share changes, diversion, arc elasticities; sensitivity curves |
| Behavioural regularity | The strong and weak regularity checks of Feng et al. (2024), with any deviation from their definition flagged |
| Reporting | A specification card per model (JSON with a schema, plus Markdown), comparison tables, VOT / sensitivity / fit-vs-prediction figures |
Nothing falls back silently. When a quantity is not defined for a model, the card records it as not applicable and says why. Examples: zero cost sensitivity, a piecewise-constant tree model.
Models and engines
| You have | Use |
|---|---|
| An MNL, nested logit or mixed logit written as a spec (JSON or dict) | BiogemeEstimator or TorchEstimator. The same spec runs on both, with identical draws |
| Any PyTorch module that returns utilities or probabilities (TasteNet, ResLogit, latent class, ...) | TorchModuleFitter. Marginal utilities come from autograd |
| A scikit-learn classifier | SklearnFitter |
| A RUMBoost model | RumboostFitter (install RUMBoost from source, see below) |
| Probabilities from elsewhere (Apollo, Stata, your own code) | PrecomputedModel |
| Anything else | Implement the four-method protocol below |
Bring your own model
A fitted model only needs to return probabilities:
import numpy as np
import pandas as pd
class EqualShares:
"""Every available alternative equally likely."""
def __init__(self, problem):
self.problem = problem
def predict_probabilities(self, data: pd.DataFrame) -> pd.DataFrame:
available = self.problem.availability_matrix(data).astype(float)
return available.div(available.sum(axis=1), axis=0)
@property
def n_params(self):
return 0
def null_loglikelihood(self, data):
return float(-np.log(self.problem.availability_matrix(data).sum(axis=1)).sum())
@property
def converged(self):
return True
Pass a fitter (a function from training data to a fitted model) to evaluate
or compare, e.g. lambda train: EqualShares(dataset.problem). A model that
also implements marginal_utilities (see dcmbench.protocols) gets
Route A VOT and posterior distributions.
Bring your own data
import dcmbench.data
from dcmbench import Attribute, ChoiceProblem
problem = ChoiceProblem(
name="my survey",
alternatives=("bus", "car"),
choice_column="choice",
choice_codes={1: "bus", 2: "car"},
attributes={
"time": Attribute({"bus": "bus_time", "car": "car_time"}, unit="minute", kind="time"),
"cost": Attribute({"bus": "bus_fare", "car": "car_cost"}, unit="USD", kind="cost"),
},
group_column="person_id", # keeps each respondent in one fold
)
# my_dataset = dcmbench.data.from_frame(my_table, problem, name="my survey", citation="...")
Units are declared once, so VOT comes out in currency per hour whatever the data's units.
Built-in datasets
dcmbench.data.load(name) downloads a versioned copy, checks its SHA-256 and
caches it (DCMBENCH_DATA_DIR, default ~/.cache/dcmbench). Every
preparation step is recorded on the dataset and on each card.
| Name | Data | Source and terms | Cite |
|---|---|---|---|
swissmetro |
Stated preference, intercity, 3 modes (6,768 obs. after prepare("benchmark")) |
EPFL TRANSP-OR (Biogeme data sets), offered for research and education | Bierlaire, Axhausen & Abay (2001) |
modecanada |
Intercity, Toronto–Montreal corridor, 4 modes (4,324 obs.) | R package mlogit (GPL-2/3), data "kindly provided by S. Koppelman" |
Bhat (1995) |
lpmc |
Revealed preference, London, 4 modes (81,086 trips; prepare("sample_5000") for the 0.1.x subsample) |
EPFL TRANSP-OR (Biogeme data sets), offered for research and education | Hillel, Elshafie & Jin (2018) |
The datasets belong to their authors. DCMBench's MIT licence covers the code, not the data. Please cite the original source when you use a dataset.
Examples
examples/ holds dataset-agnostic implementations of hybrid
models, written against the protocols above rather than shipped in the
library:
- TasteNet-MNL, ResLogit, latent class and RUMBoost, each with a check that reproduces its original paper's result;
- scikit-learn baselines;
- an MNL with the hybrids' covariates;
benchmark.py, which runs all of them on the three datasets.
tutorials/ covers internal validation (cross-validation and
bootstrap) with dcmbench.validation.
RUMBoost has no working PyPI release. Install it from source
(pip install "dcmbench[rumboost]" pins its LightGBM, then clone
RUMBoost and put it on PYTHONPATH).
DCMBench runs it in a separate worker process, so its OpenMP runtime cannot
clash with PyTorch's.
Documentation
- User guide: datasets, specs, engines, evaluation, cards.
- Adding a model and adding a dataset.
- Specification cards.
- Changelog, including the migration notes from 0.1.x.
Licence
MIT (code). See the table above for the datasets.
Metadata
Release files for dcmbench 1.0.0
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 |
|---|---|---|---|---|
| dcmbench-1.0.0.tar.gz | 105.9 kB | With provenance | Details for dcmbench-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dcmbench-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for dcmbench-1.0.0-py3-none-any.whl |
Total release size: 203.9 kB
Release files / dcmbench-1.0.0.tar.gz
| Download URL | dcmbench-1.0.0.tar.gz |
|---|---|
| Size | 105.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
34f3815e7c4893c8bc9cd74ac745da2b9f2d5b73ea68745bd0b2b6a73652b5b2
|
|
BLAKE2b-256 checksum How to use checksums |
40671fcd7981609ce4830847c48b119e0e7f507923c293c8c1f6a52a6ab3a9ce
|
| 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 9, 2026.
Transparency logRelease files / dcmbench-1.0.0-py3-none-any.whl
| Download URL | dcmbench-1.0.0-py3-none-any.whl |
|---|---|
| Size | 98.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd838d92d7e928f717c95bb6452bc8da263fc368e1b8414feeb2adc13ddd8ab7
|
|
BLAKE2b-256 checksum How to use checksums |
24da6891efabe5191e4e74a601a582972f74695eb602bed852f185c3abac5c50
|
| 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 9, 2026.
Transparency logSecurity for dcmbench 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
Both files in this release have been uploaded with provenance metadata.
Attestation for dcmbench-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 Nov 9, 2026.
Transparency logA 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.