monotonic_chi2
pg_monotonic_chi2 · Chi-square feature binning with optional monotonic event rates
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102445 | monotonic_chi2 | pg_monotonic_chi2 | 1.0 | STAT | PostgreSQL | C |
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
monotonic_chi2 1.0 fits chi-square bins for a numeric feature and a binary target. It merges low-support bins, applies adjacent ChiMerge, and optionally applies PAVA to make event rates monotonic. The repository is named pg_monotonic_chi2; the SQL extension name is monotonic_chi2.
Enable and Use
The extension contains C functions and PL/pgSQL helpers. Installation requires a superuser; it is relocatable and needs no preload or restart. Upstream does not state a supported PostgreSQL major-version range.
The second query assigns the value to bin 2. Boundaries are right-inclusive: each interval is (previous_cut, cut], and values above the last cut go into the final bin.
Table Helpers
For an existing table with numeric age and binary defaulted columns:
fit_chi2_bins groups equal finite feature values before prebinning, so ties stay together. summarize_chi2_bins returns bin_id, min_val, max_val, n_rows, events, non_events, and event_rate; its optional cutpoints argument reuses a fitted set. Use target_threshold for a continuous target: values above the threshold are events. Without it, target values must be 0/1 or Boolean.
Parameters and Boundaries
alphamust be in(0, 1),max_binsat least 1,min_pctin[0, 0.5), andn_prebinsat least 1. Their defaults are 0.05, 6, 0.05, and 100.monotonic => falseskips PAVA, which is useful for U-shaped or multi-peaked relationships.- Fitting excludes null targets and null, NaN, or infinite feature values. An empty fitting input returns an empty cutpoint array. Assignment with an empty array uses bin 1; null or NaN values return NULL. The summary puts null/NaN feature values in bin 0 and excludes null targets.
- Helpers read the supplied table with the caller’s privileges. Choose and retain cutpoints on training data before applying them to scoring data; the extension does not validate a predictive model for you.