Examples · Bands

quantile_bands · monotone_quantile_bands

Equal-population bands, and the monotone variant that merges adjacent bands until the bad rate stops going backwards.

Code#

quantile_bands.py
from _setup import latent, y_train
 
from compileml.bands import monotone_quantile_bands, quantile_bands
 
plain = quantile_bands(latent, n_bands=10)
print("quantile_bands ", len(plain.labels), "bands, no outcome data used")
 
monotone = monotone_quantile_bands(latent, y_train, n_bands=10)
rates = monotone.metadata["empirical_bad_rate"]
 
print("monotone_quantile_bands ", len(monotone.labels), "bands")
print()
print(f"{"band":<8}{"n":>8}{"bad rate":>12}")
for label, n, rate in zip(monotone.labels, monotone.metadata["counts"], rates):
print(f"{label:<8}{n:>8}{rate:>12.4f}")
 
print()
print("non-decreasing:", all(a <= b for a, b in zip(rates, rates[1:])))
print("merges applied:", monotone.metadata["merges"])

Output#

Captured from an actual run against compileml 0.9.0 and the UCI credit panel. If this script stops working, the build fails.

captured in CIquantile_bands.py
quantile_bands 10 bands, no outcome data used
monotone_quantile_bands 10 bands
 
band n bad rate
G01 2170 0.0392
G02 2328 0.0765
G03 2207 0.0961
G04 2264 0.1254
G05 2272 0.1268
G06 2259 0.1403
G07 2233 0.2136
G08 2218 0.2583
G09 2299 0.4245
G10 2250 0.7053
 
non-decreasing: True
merges applied: []

Notes#

  • monotone_quantile_bands is the default because a ladder whose bad rate dips is indefensible in a governance review.
  • Merging can return fewer bands than requested. That is the correct answer, not a failure.

API reference: monotone_quantile_bands →