Reject inference#
Supply outcomes for rejected applicants, so that a model developed on the approved applicants can be refitted on all of them. fuzzy_augmentation() and parceling() return inferred rows with weights, and reweighting() returns weights for the approved applicants.
See Reject inference for a comparison of the methods on synthetic applications.
|
Split each rejected applicant into a bad and a good row with fractional weights. |
|
Label rejected applicants bad or good at the bad rate of their score band. |
|
Weight accepted applicants to stand in for the rejected applicants of their score band. |
- kivi.reject_inference.fuzzy_augmentation(probability, *, factor=1.0)#
Split each rejected applicant into a bad and a good row with fractional weights.
The PD of a reject under the model fitted on the accepted applicants alone gives the weight of its bad row, and the rest of its weight of 1 goes to its good row. Concatenate the rows with the accepted applicants at weight 1 and refit the model with weights.
- Parameters:
- probabilityarray_like
PD of each rejected applicant under the accepts-only model, between 0 and 1.
- factorfloat, default 1
Positive multiplier of the PDs. A factor above 1 assumes that the rejects are riskier than accepted applicants with the same PD, as when the approval used information that the model does not have.
- Returns:
- pandas.DataFrame
Two rows per rejected applicant, the bad row first, with the columns
target, 1 and then 0, andweight, the PD times factor clipped to [0, 1] and its complement. The index repeats the index of probability, or its positions when it is not a Series. When probability is a Series with the unique index of the rejects,rejects.loc[result.index]gives the features of every row.
- Raises:
- ValueError
If probability is empty, not one-dimensional or not numeric, or has a value that is missing or outside [0, 1]; or if factor is not a positive finite number.
See also
parcelingInfer the outcomes from the bad rate of a score band.
reweightingWeight the accepted applicants instead.
kivi.selection.logistic_regressionRefit the model with
weights.
Notes
A reject with PD \(p\) and the factor \(k\) gets the rows
\[(y = 1,\ w = \min(k p, 1)) \quad \text{and} \quad (y = 0,\ w = 1 - \min(k p, 1)).\]Clipping keeps both weights in [0, 1]: when \(k p \ge 1\), the reject counts as bad with its whole weight and its good row has weight 0, which kivi’s
weightsarguments ignore. Each reject keeps a total weight of 1, so the weighted bad rate of its rows is the mean of \(\min(k p_i, 1)\).With
factor=1, refitting the same logistic regression on the same encoding returns the coefficients of the accepts-only model exactly: at those coefficients, the weight of each reject’s bad row equals its fitted PD, so the inferred rows leave the score equations unchanged. The refit only narrows the standard errors, although the inferred rows add no information: with these weights, the standard errors of kivi.selection.logistic_regression are too small. The model changes only with a factor other than 1, with another encoding, such as WOE refitted on the augmented sample, or with other variables.References
[1]N. Siddiqi, “Credit Risk Scorecards: Developing and Implementing Intelligent Credit Scoring”, Wiley, 2006.
Examples
>>> import pandas as pd >>> from kivi.reject_inference import fuzzy_augmentation >>> probability = pd.Series([0.1, 0.4, 0.7], index=["a", "b", "c"]) >>> fuzzy_augmentation(probability) target weight a 1 0.1 a 0 0.9 b 1 0.4 b 0 0.6 c 1 0.7 c 0 0.3 >>> fuzzy_augmentation(probability, factor=1.5).round(2) target weight a 1 0.15 a 0 0.85 b 1 0.60 b 0 0.40 c 1 1.00 c 0 0.00
- kivi.reject_inference.parceling(score, target, reject_score, *, bins=10, factor=1.0, expected=False, rng=None)#
Label rejected applicants bad or good at the bad rate of their score band.
The scores of the accepted and the rejected applicants are divided into bands. In each band, the bad rate of the rejects is factor times the observed bad rate of the accepted applicants, at most 1, and that share of the band’s rejects, chosen at random, is labelled bad.
- Parameters:
- scorearray_like
Finite numeric scores of the accepted applicants, such as their PD under the accepts-only model. The direction does not matter.
- targetarray_like
Observed outcomes of the accepted applicants, 1 for bad and 0 for good, with both present. If score and target are both pandas Series, they must have identical indices; otherwise they are matched by position.
- reject_scorearray_like
Finite numeric scores of the rejected applicants, on the scale of score.
- binsint or array_like, default 10
Number of quantile bands, fitted with kivi.binning.bin_edges on the scores of accepted and rejected applicants together, so tied scores can leave fewer bands; or increasing band edges, closed on the right, that hold every score.
- factorfloat, default 1
Positive multiplier of the accepted applicants’ bad rate in each band. A factor above 1 assumes that the rejects are riskier than accepted applicants with the same score.
- expectedbool, default False
Return two rows per reject, weighted with the band’s inferred bad rate and its complement as in fuzzy_augmentation, instead of a random label.
- rng{None, int, numpy.random.Generator}, optional
Seed or generator passed to numpy.random.default_rng to draw the labels. The global NumPy random state is not used, so the same seed gives the same labels. Not used with
expected=True.
- Returns:
- pandas.DataFrame
The columns
targetandweight, indexed like reject_score, or by position when it is not a Series. One row per rejected applicant with its label and the weight 1, or, withexpected=True, two rows per rejected applicant as returned by fuzzy_augmentation.
- Raises:
- ValueError
If score and target are invalid as for kivi.metrics.gains_table; if reject_score is empty, not one-dimensional or not numeric, or has a missing or infinite value; if bins is neither a positive integer nor at least two increasing edges, or a score lies outside the edges; if a band holds rejected applicants but no accepted one, so that its bad rate is unknown; or if factor is not a positive finite number, expected is not a boolean, or rng is not a seed or generator that numpy.random.default_rng accepts.
- Warns:
- UserWarning
If tied scores leave fewer quantile bands than bins.
See also
fuzzy_augmentationInfer the outcomes from each reject’s own PD.
reweightingWeight the accepted applicants of each band instead.
kivi.metrics.gains_tableBad rates by score band.
Notes
In a band with \(a\) accepted applicants of whom \(b\) are bad, and \(n\) rejects, the inferred bad rate is \(r = \min(k b / a, 1)\) for the factor \(k\). The number of bad rejects is \(r n\) rounded down or up at random, up with a probability equal to its fractional part, so it is \(r n\) on average and never further from it than 1. With
expected=True, each reject instead gets a bad row with the weight \(r\) and a good row with \(1 - r\), which removes the noise of the draw.Parceling uses the score only: within a band, it treats every reject alike, whatever its features. A reject’s inferred bad rate depends on the accepted applicants of its band, which are few in the bands where the approval rate is low.
References
[1]N. Siddiqi, “Credit Risk Scorecards: Developing and Implementing Intelligent Credit Scoring”, Wiley, 2006.
Examples
The accepted applicants have the bad rate 1/4 in the low band and 3/4 in the high band. Three of the four rejects of the high band are therefore labelled bad, and the one reject of the low band is bad with the probability 1/4:
>>> from kivi.reject_inference import parceling >>> score = [0.1, 0.2, 0.2, 0.3, 0.6, 0.7, 0.8, 0.9] >>> target = [0, 0, 1, 0, 1, 0, 1, 1] >>> reject_score = [0.25, 0.65, 0.75, 0.85, 0.95] >>> parceling(score, target, reject_score, bins=[0, 0.5, 1], rng=0) target weight 0 0 1.0 1 0 1.0 2 1 1.0 3 1 1.0 4 1 1.0
With
expected=True, every reject instead gets the bad rate of its band as the weight of its bad row:>>> parceling(score, target, reject_score, bins=[0, 0.5, 1], expected=True).head(4) target weight 0 1 0.25 0 0 0.75 1 1 0.75 1 0 0.25
- kivi.reject_inference.reweighting(score, reject_score, *, bins=10)#
Weight accepted applicants to stand in for the rejected applicants of their score band.
In each band of the score, every accepted applicant gets the weight (accepted + rejected) / accepted, the inverse of the band’s approval rate. The weighted accepted applicants then add up to all the applicants of their band, so a model refitted with these weights gives each band its share of the applicant population.
- Parameters:
- scorearray_like
Finite numeric scores of the accepted applicants, such as their PD under the accepts-only model. The direction does not matter.
- reject_scorearray_like
Finite numeric scores of the rejected applicants, on the scale of score.
- binsint or array_like, default 10
Number of quantile bands, fitted with kivi.binning.bin_edges on the scores of accepted and rejected applicants together, so tied scores can leave fewer bands; or increasing band edges, closed on the right, that hold every score.
- Returns:
- pandas.Series or numpy.ndarray
Weight of each accepted applicant, at least 1. A Series named
weightwith the index of score when score is a Series, otherwise an array.
- Raises:
- ValueError
If score or reject_score is empty, not one-dimensional or not numeric, or has a missing or infinite value; if bins is neither a positive integer nor at least two increasing edges, or a score lies outside the edges; or if a band holds rejected applicants but no accepted one.
- Warns:
- UserWarning
If tied scores leave fewer quantile bands than bins.
See also
fuzzy_augmentationInfer outcomes for the rejects instead.
parcelingLabel the rejects of each band at its bad rate.
kivi.selection.logistic_regressionRefit the model with
weights.
Notes
With \(a\) accepted and \(n\) rejected applicants in a band, each accepted applicant of the band gets the weight
\[w = \frac{a + n}{a}.\]Reweighting assumes that, within a band, the rejects default like the accepted applicants. It changes how much each band weighs in the fit, but adds no outcomes, so the rejects are predicted to be as risky as accepted applicants with the same score. It cannot represent applicants that no accepted applicant resembles: a band of rejects without accepted applicants raises an error. Bands of a score that decided the approval with a hard cut-off have no accepted applicants beyond the cut-off, so use a score on which accepted and rejected applicants overlap, such as the PD of the accepts-only model.
The weights add up to more than the number of accepted applicants, so the standard errors of a fit with them are too small, as if the outcomes of all applicants had been observed.
References
[1]N. Siddiqi, “Credit Risk Scorecards: Developing and Implementing Intelligent Credit Scoring”, Wiley, 2006.
Examples
The low band has 4 accepted applicants and 1 reject, the high band 2 and 4:
>>> from kivi.reject_inference import reweighting >>> score = [0.1, 0.2, 0.2, 0.3, 0.6, 0.7] >>> reweighting(score, [0.25, 0.65, 0.75, 0.85, 0.95], bins=[0, 0.5, 1]) array([1.25, 1.25, 1.25, 1.25, 3. , 3. ])