hosmer_lemeshow_test
Note
This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the Habitat Guide and Python API guide (v2.0) for usage.
- hosmer_lemeshow_test(y_true: ndarray, y_prob: ndarray, n_groups: int = 10) Tuple[float, float][source]
Perform the Hosmer-Lemeshow calibration test for binary outcomes.
Subjects are grouped into
n_groupsquantile-based risk groups (right-closed intervals, lowest edge included, mirroringpd.qcut), then the chi-square statistic comparing observed and expected event counts is evaluated againstn_groups - 2degrees of freedom.- Parameters:
y_true – Binary outcomes (0/1).
y_prob – Predicted event probabilities, aligned to
y_true.n_groups – Number of risk groups (classically 10, the decile test).
- Returns:
Tuple
(statistic, p_value).- Raises:
ValueError – If inputs are misaligned, non-binary, probabilities fall outside [0, 1], or the quantile edges are not unique (too many tied probabilities to form
n_groupsgroups).