Credit-risk, churn and fraud teams screen candidate features by how well each one separates the two classes. The standard screen for a binned feature is Weight of Evidence per bin and the Information Value of the whole feature.
Implement woe_iv(bins, target, smoothing=0.5).
Inputs
bins: list of bin labels, one per row (all strings or all ints).target: list of 0/1 of the same length; 1 is the event (bad: default, churn, fraud) and 0 is the non-event (good).smoothing: a positive float added to the good count and to the bad count of every bin before anything else is computed.Definitions. For bin with smoothed counts (goods) and (bads), and totals , :
Output: a dict
"woe": {bin: WoE} with keys in sorted order, values rounded to 4 decimals,"iv": the IV rounded to 4 decimals,"strength": "useless" if IV , "weak" if , "medium" if , "strong" if , else "suspicious". Use the unrounded IV for this.The input has at least one row.