Critical Difference diagram generator in pure Python
Project description
cddiagram
A pure Python library for generating Critical Difference (CD) diagrams as SVG.
CD diagrams visualize the statistical comparison of multiple classifiers (or models) over multiple datasets, as introduced by Demsar (2006). They show the average rank of each model and connect groups of models whose performance differences are not statistically significant.
J. Demsar, "Statistical Comparisons of Classifiers over Multiple Data Sets", Journal of Machine Learning Research, vol. 7, pp. 1-30, 2006. https://jmlr.org/papers/v7/demsar06a.html
How it works
- A Friedman test checks whether at least one model differs significantly from the others (at alpha = 0.05).
- If significant, the Nemenyi post-hoc test computes a critical distance (CD) threshold.
- Models whose average rank difference is less than CD are grouped together — they are not statistically distinguishable.
- The result is rendered as an SVG diagram showing ranked models and significance groups.
Install
pip install cddiagram
Requires Python 3.12+ and depends on numpy and scipy.
Usage
Write to file
import numpy as np
from cddiagram import draw_cd_diagram
rng = np.random.default_rng(1)
models = {
"model1": rng.normal(loc=0.2, scale=0.1, size=30),
"model2": rng.normal(loc=0.2, scale=0.1, size=30),
"model3": rng.normal(loc=0.4, scale=0.1, size=30),
"model4": rng.normal(loc=0.5, scale=0.1, size=30),
"model5": rng.normal(loc=0.7, scale=0.1, size=30),
"model6": rng.normal(loc=0.7, scale=0.1, size=30),
"model7": rng.normal(loc=0.8, scale=0.1, size=30),
"model8": rng.normal(loc=0.9, scale=0.1, size=30),
}
samples = np.column_stack(list(models.values()))
draw_cd_diagram(samples, labels=list(models.keys()), out_file="out.svg", title="Model comparison")
Non-significant results
If the Friedman test is not significant, the function issues a warning and returns None — no diagram is produced because the data does not support ranking the models.
API
draw_cd_diagram(
samples, # 2D array-like (rows=datasets, columns=models)
labels, # Sequence of model names (one per column)
title=None, # Optional diagram title
out_file=None, # Optional path to write SVG file
fig_size=None, # Optional (width, height) tuple in pixels
) -> Element | None
Input formats: NumPy arrays, pandas DataFrames, or any object with a .to_numpy() / .values attribute.
Release Notes
0.0.7
- Optimized Nemenyi critical-value computation with a precomputed
q_alphalookup table fork=3..100atalpha=0.05. - Kept a SciPy
studentized_rangefallback for values outside the lookup range (or different alpha), preserving behavior for all valid inputs.
0.0.6
- Red clique bars now render on top of all other SVG elements (connectors, markers, axis).
0.0.5
- Text labels no longer carry an SVG stroke, removing the bold/smudged appearance.
font-family="sans-serif"set globally for consistent cross-platform rendering.- Empty title no longer emits a stray
<text/>node. - Non-maximal cliques filtered out — only strictly maximal non-significance groups are drawn, eliminating near-duplicate bars.
- Classifier connectors use a single
<polyline>withstroke-linejoin="miter", removing the corner notch produced by two separate lines. - Axis markers are taller than the axis stroke so they are visible.
- Clique end-caps enlarged for legibility.
- CD-bar tick length unified with ruler tick length.
- Label-width heuristic bumped to better fit sans-serif glyphs.
0.0.4
- Non-significant groups packed into the minimum number of rows (greedy interval scheduling).
- Fixed vertical layout: title → CD bar → ruler → groups → labels (groups now drawn below the axis).
0.0.2
- Replaced hardcoded Nemenyi critical-value lookup table with SciPy's
studentized_rangecomputation. - Updated CD diagram drawing to follow continuous rank-axis placement and first-anchor non-significant grouping.
- Improved readability for larger numbers of algorithms with adaptive multi-row label layout.
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cddiagram-0.0.7.tar.gz.
File metadata
- Download URL: cddiagram-0.0.7.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
362a109482a90d2482df6f583bef001b2d336ee04a25e08ee88ba417187fd380
|
|
| MD5 |
d18fddf2047afcdf94d5885219071cd7
|
|
| BLAKE2b-256 |
80ba90fb5bd28c2a8266ec85d7ee5e17d8997f0dc4e8ddbf3d3038dc6e162288
|
Provenance
The following attestation bundles were made for cddiagram-0.0.7.tar.gz:
Publisher:
publish-pypi.yml on irazza/cddiagram
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cddiagram-0.0.7.tar.gz -
Subject digest:
362a109482a90d2482df6f583bef001b2d336ee04a25e08ee88ba417187fd380 - Sigstore transparency entry: 1348558637
- Sigstore integration time:
-
Permalink:
irazza/cddiagram@6db9752c36fc77c8a13c1eccc1d78c5c5075d8ec -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/irazza
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@6db9752c36fc77c8a13c1eccc1d78c5c5075d8ec -
Trigger Event:
release
-
Statement type:
File details
Details for the file cddiagram-0.0.7-py3-none-any.whl.
File metadata
- Download URL: cddiagram-0.0.7-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34cd4daf6c006ee4bd25066d9048013dc02f005f97c9e65bc66e757c35601f19
|
|
| MD5 |
1bb24ecbc7f11159b77ee7a56e535553
|
|
| BLAKE2b-256 |
def7298a9b8c1647d990124438bd46debb1a36cbe0abbc6eea2a4648a55c88b0
|
Provenance
The following attestation bundles were made for cddiagram-0.0.7-py3-none-any.whl:
Publisher:
publish-pypi.yml on irazza/cddiagram
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cddiagram-0.0.7-py3-none-any.whl -
Subject digest:
34cd4daf6c006ee4bd25066d9048013dc02f005f97c9e65bc66e757c35601f19 - Sigstore transparency entry: 1348558694
- Sigstore integration time:
-
Permalink:
irazza/cddiagram@6db9752c36fc77c8a13c1eccc1d78c5c5075d8ec -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/irazza
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@6db9752c36fc77c8a13c1eccc1d78c5c5075d8ec -
Trigger Event:
release
-
Statement type: