Lesson 6.1: Build a logistic regression scorecard
Fit a logistic regression on weight-of-evidence inputs, read coefficients, standard errors and signs, spot collinearity, and test the model on a holdout.
By the end of this lesson you will be able to fit a logistic regression scorecard from weight-of-evidence inputs, write down the model in the form a scorecard uses, read each coefficient, its standard error and its sign, explain why some coefficients come out close to one and others do not, detect and handle correlation between inputs, test the model on a holdout sample and calculate the probability of default for a single applicant by hand. You should have read Lessons 5.1 to 5.3, which produced the bins, the weight of evidence and the shortlist of characteristics. The lesson uses logarithms and exponentials, and every figure comes from a worked calculation that you can reproduce.
Module 5 prepared the ingredients. Each characteristic now has a handful of bins, and each bin has a weight of evidence, a number that says how much safer or riskier than average the bin is. This lesson combines them. The tool is logistic regression, a statistical model that predicts a yes or no outcome, here good or bad, from a set of inputs. It has been the workhorse of credit scoring for decades, because it is accurate enough, easy to explain and easy to turn into a table of points, which Lesson 6.2 does.
About the data in this module
Lessons 6.1 to 6.3 use one synthetic dataset that was built for this course to match the examples of Module 5. It has 10,000 personal loans, of which 1,000 are bad (a bad rate of 10 per cent). The utilisation bins, with bad counts of 90, 130, 175, 250 and 355 out of 2,000 loans each, are exactly those of Lesson 5.1, and home ownership follows Lesson 5.2. Three more characteristics were added: the number of credit enquiries in the last six months, a band of monthly income and whether the borrower has a short or long credit history. The data were split at random into a development sample of 7,000 loans (687 bad) and a holdout sample of 3,000 loans (313 bad). All weights of evidence and coefficients come from the development sample. Because the data are synthetic, the results show how the method behaves, and they are not statistics about real borrowers.
The model
Logistic regression models the log odds of an outcome as a straight-line sum of inputs. In scorecard work, the inputs are the weights of evidence of Lesson 5.2, and the outcome modelled is "good" so that a larger value means a safer borrower:
> ln( odds of good ) = β₀ + β₁ × WoE₁ + β₂ × WoE₂ + … + β₅ × WoE₅
The odds of good are the probability of good divided by the probability of bad, as in Lesson 5.2. The model gives a probability of default (PD) for any applicant once you know the bin each characteristic falls into:
> Odds of good = e raised to the power of the sum; PD = 1 ÷ (1 + odds of good)
The coefficients β are found by the computer, which chooses them to make the observed pattern of goods and bads as likely as possible, a method called maximum likelihood. You do not need the mathematics, but you need to read the output.
Using weight of evidence as input has a convenient consequence. A WoE is already a log odds, and it is already in the right direction (positive for safer bins). If the characteristics were independent of one another once you know the outcome, the right coefficient for each would be exactly one, and the intercept would be the log odds of the whole sample, ln(9) = 2.20 for a 10 per cent bad rate. Real data never behave quite like this, and the departures from one are informative.
The five characteristics
In the development sample, the characteristics and their information values are as follows.
Characteristic · Bins · Information valueCredit utilisation · 5 · 0.293
Credit enquiries in the last 6 months · 4 · 0.349
Home ownership · 2 (owned, rented or with family) · 0.086
Monthly income band · 4 · 0.066
Credit history (long or short) · 2 · 0.194
The weights of evidence of each bin, from the safest to the riskiest, are:
Characteristic · Weight of evidence by binUtilisation (0–20, 20–40, 40–60, 60–80, 80%+) · +0.860, +0.545, +0.137, −0.263, −0.681
Enquiries (fewest to most, four bands) · +0.916, +0.515, −0.194, −0.649
Home (owned; rented or with family) · +0.414, −0.208
Income (lowest to highest band) · −0.315, −0.104, +0.162, +0.366
History (long; short) · +0.359, −0.547
All five pass the rules of Lesson 5.3: each has an IV above 0.02, the WoE moves in a sensible direction and the bins are large enough. A modeller would also have checked stability across periods, which cannot be done on a single synthetic sample, and the fairness and leakage questions.
The fitted model
Fitting the logistic regression on the 7,000 development loans gives the following result.
Term · Coefficient · Standard error · z-valueIntercept · 2.218 · 0.044 · 50.5
Utilisation WoE · 0.532 · 0.099 · 5.4
Enquiries WoE · 0.696 · 0.092 · 7.6
Home ownership WoE · 0.955 · 0.148 · 6.4
Income WoE · 0.967 · 0.164 · 5.9
History WoE · 0.987 · 0.092 · 10.7
Reading the table takes four questions.
1. Are the signs right? Every coefficient is positive. Since a higher WoE means safer, a positive coefficient means that a safer bin raises the log odds of good, exactly what we want. A negative coefficient on a WoE input would be a warning, because it would say that being in a safer bin makes a borrower riskier, once the other variables are held fixed. That nearly always means two inputs are measuring the same thing, and the model is arguing with itself.
2. Are the coefficients significant? The z-value is the coefficient divided by its standard error. As a rule of thumb, a value beyond about 2 (in either direction) means the coefficient is unlikely to be zero by chance. All five z-values here are above 5, so every characteristic is clearly contributing. The standard error is large when the characteristic has few bads in some bins or when it is correlated with another input.
3. Are the sizes sensible? The intercept of 2.218 is close to the 2.20 expected from a 10 per cent bad rate, a good sign. Three coefficients are within 5 per cent of 1: home ownership (0.955), income (0.967) and history (0.987). These characteristics are almost independent of the others, so each is used at face value. Utilisation (0.532) and enquiries (0.696) are noticeably smaller than 1. Why?
4. What explains the departure from 1? Check the correlations between the weights of evidence.
Pair · CorrelationUtilisation and enquiries · 0.63
Every other pair · 0.04 or less
Borrowers who use most of their credit limits also tend to have made many recent enquiries. The two characteristics share a message: "this borrower is stretched for credit". If the model counted each at full strength, it would count that message nearly twice. The regression shares the credit between them, giving each a coefficient below 1. The sum of the two matters: if enquiries were dropped, the utilisation coefficient would rise.
Predict first: if you dropped enquiries from the model altogether, would the coefficient on utilisation go up, go down or stay the same? Think about the shared message before reading on.
It would go up, because utilisation would then carry the whole of the shared signal, and the model would also lose some accuracy because enquiries carries information that utilisation does not. This is the usual pattern when two inputs overlap, and the reason that a scorecard builder watches for correlated pairs before fitting, as in Lesson 5.3.
Handling correlated inputs
Correlation between inputs does not break a model that is used only to predict, since the combined prediction is still sound. It causes trouble in three ways: coefficients become unstable (they change a lot with small changes in the data), they are hard to explain ("why does a higher utilisation help here?") and they may take the wrong sign. There are several remedies.
Keep both and accept lower coefficients, as here, when the signs are right, the sizes are stable and the correlation is moderate. A correlation of 0.63 is moderate.
Drop one of a highly correlated pair, usually the one with the lower IV or the weaker business meaning. A rule of thumb is to look closely at correlations above 0.7 or so.
Combine them into a single measure, such as a "credit stress" index, or the average of the two weights of evidence.
Check the variance inflation factor, a number that says how much the variance of a coefficient is inflated by the correlation with other inputs. Values above about 5 or 10 are a warning, depending on the lender's policy. Here, with a correlation of 0.63, the factor for the two overlapping inputs is about 1 ÷ (1 − 0.63²) = 1.66, which is mild.
Another useful check is stability: refit the model on a random half of the development sample, then on the other half, and compare the coefficients. If they swing wildly, the model is fragile.
Using the model for one applicant
The best test of your understanding is to compute the PD for a single applicant by hand. Take an applicant with the following characteristics:
Utilisation 60 to 80 per cent: WoE −0.263
Enquiries in the third band: WoE −0.194
Home: rented, so WoE −0.208
Income in the second band: WoE −0.104
Credit history: short, so WoE −0.547
Compute the contribution of each characteristic, the coefficient times the WoE:
Utilisation: 0.532 × (−0.263) = −0.140
Enquiries: 0.696 × (−0.194) = −0.135
Home: 0.955 × (−0.208) = −0.199
Income: 0.967 × (−0.104) = −0.101
History: 0.987 × (−0.547) = −0.540
The log odds of good are 2.218 − 0.140 − 0.135 − 0.199 − 0.101 − 0.540 = 1.104. The odds of good are e^1.104 = 3.02, which is about 3 goods for each bad, and the PD is 1 ÷ (1 + 3.02) = 24.9 per cent. This applicant is about two and a half times as risky as the average borrower at 10 per cent.
The simulator below repeats the calculation. Change the weight of evidence of each characteristic, for instance to the most favourable bin of each, and watch the probability of default fall.
Set every WoE to its safest value (+0.860, +0.916, +0.414, +0.366, +0.359) and the PD drops to about 1.2 per cent. Set every WoE to its riskiest value (−0.681, −0.649, −0.208, −0.315, −0.547) and it climbs to about 41 per cent. That spread, from 1 per cent to 41 per cent, is what the model has learned.
Checking the model on the holdout sample
A model must be tested on data it has not seen, or it can look good simply because it has memorised the development sample. The holdout sample of 3,000 loans played no part in choosing the bins, the weights of evidence or the coefficients. Two summary measures compare the ranking of borrowers with what actually happened: the AUC, the chance that a randomly chosen bad loan receives a riskier score than a randomly chosen good loan, and the KS statistic, the largest gap between the cumulative shares of bad and good loans as you move down the risk ranking. Module 7 defines both properly. For now, higher is better, 0.5 for the AUC means no skill and 1 means perfect.
Sample · AUCUtilisation alone (holdout) · 0.632
The five-variable model, development sample · 0.724
The five-variable model, holdout sample · 0.692
The KS statistic on the holdout sample is 0.285. Two points stand out. First, combining five characteristics lifts the AUC from 0.632 for utilisation alone to 0.692, so the extra variables are earning their place. Second, the holdout AUC (0.692) is lower than the development AUC (0.724), a gap of 0.032. A small drop is normal, because the model has been tuned to the development data. A large drop, such as 0.724 to 0.62, would suggest overfitting, or a difference between the two samples. If the holdout is consistently much worse, the model should be simplified.
Building it in Python
The fit takes a few lines with a standard statistics library.
python
import numpy as np
import pandas as pd
import statsmodels.api as sm
dev = pd.readcsv("developmentwoe.csv") # columns: bad (1/0), utilwoe, enqwoe, homewoe, incomewoe, historywoe
hold = pd.readcsv("holdoutwoe.csv")
features = ["utilwoe", "enqwoe", "homewoe", "incomewoe", "historywoe"]
X = sm.addconstant(dev[features])
y = 1 - dev["bad"] # model the log odds of GOOD
model = sm.Logit(y, X).fit()
print(model.summary()) # coefficients, standard errors, z-values
correlation of the inputs
print(dev[features].corr().round(2))
variance inflation factors
from statsmodels.stats.outliersinfluence import varianceinflationfactor
Xv = dev[features].assign(const=1.0)
vif = {c: varianceinflationfactor(Xv.values, i) for i, c in enumerate(Xv.columns) if c != "const"}
print(vif)
probability of default on the holdout sample, and AUC
from sklearn.metrics import rocaucscore
hold["pd"] = 1 - model.predict(sm.addconstant(hold[features]))
print("Holdout AUC:", round(rocaucscore(hold["bad"], hold["pd"]), 3))
Check three things in the output before you do anything else: every coefficient has the expected positive sign, the z-values are large, and the VIFs are low. Then compare the AUC on the development and the holdout samples. Save the intercept, the coefficients and the table of bin edges and weights of evidence, because the production system must apply exactly the same mapping.
A worked example: when a sign comes out wrong
Suppose a modeller, using a different dataset, fits the same five characteristics and gets a negative coefficient of −0.39 for utilisation, together with a large coefficient of 1.16 on enquiries, because her enquiries variable is far more strongly related to default and also strongly correlated with utilisation (0.74). What should she do?
1. Do not accept it. A negative coefficient says that, with enquiries held fixed, a higher-utilisation bin is safer. That is a statistical artefact of the overlap and makes no business sense, and a credit officer would reject the scorecard.
2. Check the correlation and the VIF. A correlation of 0.74 is above the usual threshold of about 0.7.
3. Try the remedies. Drop utilisation or enquiries and refit, or combine them into one stress measure, or refit with a constraint that all coefficients be positive. Compare the AUC on the holdout in each case. In this kind of situation, a simpler model with one of the two usually gives nearly the same AUC with stable, explainable coefficients.
4. Document the decision. Record which was dropped, why, and what the AUC cost.
This is the reason that every scorecard report includes the signs, the correlations and the reasoning. The numbers must tell a story that a risk committee can accept.
Common mistakes
Fitting on raw variables instead of weight of evidence. The scorecard framework assumes WoE inputs, and the coefficients and points depend on it.
Ignoring the sign of a coefficient. A negative coefficient on a WoE input is a warning of overlap, not a finding.
Treating all coefficients as comparable. They depend on the scale of the WoE, which varies by characteristic.
Judging the model on the development sample alone. Always check a holdout.
Keeping highly correlated inputs. The coefficients become unstable and hard to explain.
Letting the data choose the model entirely. Business sense, stability and explainability matter as much as the fit.
Forgetting to save the mapping. Production must use the same bins, weights of evidence and coefficients.
Mixing up good and bad. Be sure whether the model predicts good or bad, since this reverses every sign.
Key takeaways
A logistic regression scorecard models the log odds of good as an intercept plus a coefficient times the weight of evidence of each characteristic.
Read the signs, the z-values and the sizes. With weight of evidence inputs, coefficients near 1 mean a characteristic is used at face value.
In the synthetic example, home ownership, income and history had coefficients near 1, while utilisation (0.53) and enquiries (0.70) were lower because they correlate at 0.63.
A negative coefficient on a WoE input is a warning of overlapping variables. Check correlations and variance inflation factors, and drop, combine or constrain.
PD for one applicant is 1 ÷ (1 + e^(log odds)). The worked applicant had log odds of 1.104 and a PD of 24.9 per cent.
Test on a holdout. The five-variable model scored an AUC of 0.724 on development and 0.692 on holdout, against 0.632 for utilisation alone.
Check yourself
1. A model has an intercept of 2.2 and a single characteristic with a coefficient of 1 and a WoE of −0.5. What are the log odds of good and the PD?
Log odds 2.2 − 0.5 = 1.7. Odds e^1.7 = 5.47. PD = 1 ÷ 6.47 = 15.5 per cent.
2. Why does a coefficient below 1 often point to an overlap with another input?
If two inputs carry the same message, the model shares the weight between them, so each coefficient shrinks. Independent inputs would each get a coefficient near 1.
3. What does it mean if a WoE input gets a negative coefficient?
Holding the other inputs fixed, the safer bin is associated with higher risk. This usually signals strong correlation with another input, and calls for dropping, combining or constraining.
4. The development AUC is 0.78 and the holdout AUC is 0.66. What does this suggest?
Overfitting, or a difference between the samples. Simplify the model, check the split and test again.
5. An applicant's log odds of good are 0.5. What are the odds and the PD?
Odds e^0.5 = 1.65, so PD = 1 ÷ 2.65 = 37.8 per cent.
Try this
Fit and read a scorecard model of your own. Set aside forty to fifty minutes.
1. Take the WoE-transformed data you built in Module 5, or invent a table of at least 2,000 loans with three to five WoE columns and a bad flag. Split it 70 per cent for development and 30 per cent for holdout.
2. Compute the correlation matrix of the inputs. Mark any pair above 0.6 and decide in advance what you would do about it.
3. Fit the logistic regression on the development sample, modelling good. Record the intercept, the coefficients, the standard errors and the z-values.
4. Check every sign and every size against your expectation of 1. Write one sentence for each coefficient that is far from 1.
5. Compute the AUC on both samples. Write the gap and say whether you consider it acceptable.
6. Pick one applicant, compute the log odds and the PD by hand, and check the result with the simulator pattern or your code.
7. Write a five-sentence model note: the characteristics, the signs, the one correlated pair and what you did about it, the AUC on both samples and one check you would run before using the model.
A good result is a coefficient table you can explain line by line, a holdout AUC close to the development AUC and a hand calculation that matches the computer. Lesson 6.2 turns this model into the table of points that credit officers use.
Tags: Credit Risk Analytics Logistic Regression Scorecard Weight of Evidence Model Building