# 022. Subscription probability calibration

**Question:** Do predicted probability bands match observed subscriptions on later records?

## Result

The largest computed metric is 0.3327 for (0.122, 0.184]; the smallest is 0.04992 for (0.0951, 0.102]. Metric: absolute_gap (Absolute calibration gap).

These are diagnostics on a previously defined test set, not a new independent experiment.

![Subscription probability calibration](outputs/chart.png)

| bin | n | predicted_probability | observed_rate | absolute_gap |
| --- | --- | --- | --- | --- |
| (0.00081, 0.0312] | 905 | 0.02366 | 0.1867 | 0.1631 |
| (0.0312, 0.0388] | 904 | 0.0345 | 0.1648 | 0.1303 |
| (0.0388, 0.0561] | 904 | 0.04717 | 0.2754 | 0.2283 |
| (0.0561, 0.0736] | 912 | 0.0635 | 0.3191 | 0.2556 |
| (0.0736, 0.0951] | 948 | 0.08717 | 0.1899 | 0.1027 |
| (0.0951, 0.102] | 859 | 0.09909 | 0.149 | 0.04992 |
| (0.102, 0.122] | 898 | 0.1096 | 0.2539 | 0.1443 |
| (0.122, 0.184] | 904 | 0.1441 | 0.4768 | 0.3327 |
| (0.184, 0.41] | 904 | 0.2896 | 0.6073 | 0.3177 |
| (0.41, 0.926] | 905 | 0.6336 | 0.5326 | 0.101 |

The chart shows 10 of 10 result rows; the table previews the first 10 in the analysis-defined order. [Download the full result table](outputs/results.csv). Numerical values are computed from the source; missing results stay unavailable.

## Method

Reliability table for a fixed logistic model, with equal-frequency probability bins.

The study uses shared source preparation and reusable statistical routines. Its specific transformations are in [analysis.py](analysis.py), and common model/evaluation code is in [portfolio/methods.py](../../portfolio/methods.py). The [notebook](analysis.ipynb) executes the study and displays the saved results.

## Evaluation

First 80% of ordered observations train; final 20% test. Training observations: 36,168; test observations: 9,043. Fixed models; default decision threshold; no holdout tuning.

Target: `subscribed`. Features: contact, month, day, campaign, pdays, previous, poutcome. Model results and row membership are recorded in [evaluation.json](outputs/evaluation.json).

## Decision and limitations

Check calibration on new campaigns before interpreting probabilities as expected response rates.

Observational marketing records do not identify campaign uplift. Month and row order are not precise timestamps; repeated-client identifiers are unavailable. Models are research diagnostics, not financial eligibility or automated contact decisions. 

Related studies may share observations or holdouts. These are focused analytical studies, not independent replications or deployed business systems. Any model refinements informed by these results need new untouched evaluation data. No commercial impact is inferred from an association or backtest.

## Reproduce

From the repository root, after installing `requirements.txt`:

```powershell
python projects/022-subscription-probability-calibration/analysis.py
```

Source data are downloaded automatically if absent. Original archives are retained unchanged and checked by SHA-256. The cleaned cache normalizes column names; field-specific changes are visible in [data preparation](../../portfolio/data.py). Runtime evidence is in [receipt.json](outputs/receipt.json).

## Source

[Bank Marketing](https://archive.ics.uci.edu/dataset/222/bank+marketing), Moro, Rita and Cortez (2014). [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). Source data are transformed and aggregated in this study. [Source provenance](../../data/provenance/bank.json) and [prepared-data audit](../../data/provenance/bank_prepared.json) record the downloaded files, field coverage and hashes.
