Lesson 5.1: Binning variables for a credit scorecard
Learn why scorecards group variables into bins, how to move from fine to coarse classing, and the rules for bins that are stable, sensible and large enough.
By the end of this lesson you will be able to take a raw variable from a loan application, such as the share of a credit limit already used, and turn it into a small number of bins that a scorecard can use. You will know the main ways of cutting a variable, how to start with many fine classes and merge them into a few coarse ones, how to test whether two neighbouring bins really differ, how to give missing values a bin of their own, and how many loans a bin needs before its bad rate can be trusted. You should have read Lesson 2.2, which profiled single variables, and Lesson 2.3, which related them to default. The arithmetic is counting and proportions, and every table here is small enough to rebuild by hand.
Modules 3 and 4 measured loss and migration on a book that already existed. Module 5 starts the other half of credit risk analytics: predicting, at the moment of application, which borrowers are likely to default. The classic tool is the scorecard, a list of characteristics, each with a table of points. Before any points can be given, each characteristic has to be cut into groups. This is binning, and it is the step on which the rest of the scorecard depends. A weak binning produces a weak scorecard, whatever the quality of the statistics that follow.
Why scorecards use bins
A modeller could feed raw numbers straight into a logistic regression. Scorecard builders choose not to, for five reasons.
1. Relationships are rarely straight lines. Default risk does not rise evenly with utilisation, age or income. It might be flat at low levels, steep in the middle and flat again at the top. A bin lets each stretch of the variable have its own effect without the modeller choosing a curve.
2. Outliers lose their power. A stated income of ₹90 crore on a personal loan application is almost certainly an error. In a bin labelled "above ₹1 lakh a month" it is harmless.
3. Missing values can be used. A blank is often informative. Applicants who leave a field empty can be riskier or safer than average, and a missing-value bin lets the model learn which.
4. Scores can be explained. A rejected applicant can be told that a utilisation above 80 per cent cost them points. A coefficient on a raw number is harder to explain, and regulators ask for explanations.
5. The model becomes stable. Small movements in a raw number change a score a little, but a bin edge is a step. Steps are easy to monitor, as Module 8 will show, and they limit the damage from drift.
The price is a loss of detail. A bin treats an applicant at 61 per cent utilisation and one at 79 per cent alike. The art of binning is to choose bins coarse enough to be stable and fine enough to keep the signal.
Four ways of cutting a variable
Equal-width bins divide the range into slices of the same size, for example every ₹20,000 of monthly income. They are simple, and they behave badly with skewed data. Most variables in lending are skewed: many people with modest incomes, a few with very large ones.
Take 10,000 loans and cut monthly income into equal slices of ₹20,000.
Income band · Loans · Bad loansBelow ₹20,000 · 4,200 · 520
₹20,000 to ₹39,999 · 3,100 · 330
₹40,000 to ₹59,999 · 1,500 · 100
₹60,000 to ₹79,999 · 700 · 35
₹80,000 to ₹99,999 · 300 · 10
₹1 lakh and above · 200 · 5
Total · 10,000 · 1,000
The top band has 200 loans and only 5 bad ones. Its bad rate is 2.5 per cent, but with so few bads it cannot be trusted: the standard error of a proportion of 2.5 per cent from 200 loans is the square root of 0.025 × 0.975 ÷ 200, which is about 1.1 points. A 95 per cent range runs from near 0.3 to 4.7 per cent. The bin could be anywhere from nearly risk-free to about as risky as the ₹60,000 band, and a scorecard built on it would reward the wrong thing.
Equal-frequency bins, also called quantiles, put the same number of loans in each bin. With five bins here, each would hold 2,000 loans and about 200 bads. Each bin's bad rate is then measured with similar precision. The cost is that the edges fall at odd values, such as ₹11,240, that nobody would choose by judgement. Many analysts start from quantiles and round the edges afterwards.
Business bins use cut-offs that the lender already uses, such as age bands for policy reasons, a minimum salary for a product, or a standard 30, 60, 90 days past due. They are easy to explain and tie to policy. They are not always optimal statistically.
Optimal or supervised bins let an algorithm search for cut points that best separate good and bad loans, often with a decision tree of limited depth, under constraints on bin size and order. They are the usual choice in practice, followed by a check by a human.
Fine classing, then coarse classing
The standard workflow has two stages, and the names come from the scorecard literature.
Fine classing cuts the variable into many narrow bins, often 10 to 20, using equal frequency. The aim is to see the shape of the relationship without committing to anything.
Coarse classing merges neighbouring fine bins into a few groups, usually four to eight, so that each coarse bin is large, differs from its neighbours, and tells a story that makes business sense.
Work through an example. The variable is credit utilisation: the share of the borrower's existing revolving credit limits that is in use, as reported by a credit bureau. The data are 10,000 personal loans with 1,000 bad (a bad rate of 10 per cent). Ten equal-frequency fine bins of 1,000 loans each give the following.
Fine bin · Utilisation · Loans · Bad loans · Bad rate1 · 0 to 10% · 1,000 · 40 · 4.0%
2 · 10 to 20% · 1,000 · 50 · 5.0%
3 · 20 to 30% · 1,000 · 60 · 6.0%
4 · 30 to 40% · 1,000 · 70 · 7.0%
5 · 40 to 50% · 1,000 · 80 · 8.0%
6 · 50 to 60% · 1,000 · 95 · 9.5%
7 · 60 to 70% · 1,000 · 110 · 11.0%
8 · 70 to 80% · 1,000 · 140 · 14.0%
9 · 80 to 90% · 1,000 · 180 · 18.0%
10 · 90% and above · 1,000 · 175 · 17.5%
The pattern is clear: the more of their limit people use, the riskier they are. The ten bins also add up: the loans total 10,000 and the bads total 1,000. But the last two bins break the rule. Bin 10 has a lower bad rate (17.5 per cent) than bin 9 (18.0 per cent), though people near the limit should be at least as risky as those a little below it.
Predict first: should bins 9 and 10 be kept apart because their bad rates differ, or merged? Think about the size of the gap and the size of the noise before you read on.
The gap is half a percentage point. The noise in each bin's bad rate is about the square root of 0.18 × 0.82 ÷ 1,000, which is 1.2 points. A gap of 0.5 is well inside the noise, and the direction goes against what business sense says. The bins should be merged. A formal check uses a z-score for the difference between two proportions, shown in the simulator below.
Change the bad loans in the second bin from 175 to 120 and watch the z-score pass 2: now the bins are really different and should stay apart. A common working rule is to merge neighbours whose z-score is below 2 and to merge any bin that breaks the expected order of risk.
Now merge the fine bins into five coarse bins, joining neighbours with similar rates.
Coarse bin · Utilisation · Loans · Bad loans · Bad rateA · 0 to 20% · 2,000 · 90 · 4.50%
B · 20 to 40% · 2,000 · 130 · 6.50%
C · 40 to 60% · 2,000 · 175 · 8.75%
D · 60 to 80% · 2,000 · 250 · 12.50%
E · 80% and above · 2,000 · 355 · 17.75%
Check the totals: loans 10,000, bads 90 + 130 + 175 + 250 + 355 = 1,000. Check the rates: 90 ÷ 2,000 = 4.50 per cent, 355 ÷ 2,000 = 17.75 per cent.
The coarse version is monotonic, every bin holds 20 per cent of the loans, and each has at least 90 bad loans. Lesson 5.2 will convert these bad rates into the numbers a model uses.
Rules for good bins
Experienced scorecard builders apply a short list of rules. They are not laws of nature, but a bin that breaks one deserves a reason.
1. Enough loans. Each bin should hold a reasonable share of the sample, commonly at least 5 per cent. Tiny bins are unstable.
2. Enough bads. Each bin should hold a minimum number of bad loans, often 30 or more, and in demanding settings more than that. The bad rate of a bin with 5 bads is dominated by chance. The simulator below shows how the margin of error shrinks as bins grow.
3. Different from neighbours. Adjacent bins should have clearly different bad rates, tested as above. Bins that do not differ should be merged, since they add complexity without information.
4. A sensible order. For variables with a natural direction, such as utilisation, the bad rate should rise or fall steadily across the bins. A zig-zag usually means noise. Some variables are legitimately non-monotonic, as with age, where the very young and the very old can both be riskier, and the shape should then be explainable.
5. Stable over time. A bin that holds 20 per cent of applicants this year and 6 per cent next year is a warning. Check the distribution by period, using the stability measures of Module 8.
6. Business logic. Each bin should be describable in a sentence a credit officer accepts. Edges should fall on round, memorable numbers where possible.
7. Special values get their own bin. Missing, not applicable, zero and error codes should not be mixed with real values, as the next section explains.
At the default of 1,000 loans and a 10 per cent bad rate the margin is plus or minus 1.9 points. At 200 loans it is plus or minus 4.2 points, which is wider than the gap between most neighbouring bins in the utilisation table. The curve flattens beyond a few thousand loans, so adding data to a bin that already has plenty gives little extra precision, while adding data to a tiny bin helps a lot.
Missing and special values
Blanks deserve more care than most beginners give them. There are three tempting mistakes: delete the loans with a missing value, replace the blanks with the average, or lump them in with the lowest bin. Each destroys information.
Take the variable months at current employer. Of the 10,000 loans, 800 have no value. Among those 800, 128 are bad, a bad rate of 16.0 per cent, compared with 10.0 per cent overall. People who leave the field blank are riskier than average. If the blanks were filled with the average tenure, they would join the mid-tenure bin, whose bad rate might be 9 per cent, and the extra risk would be hidden. If the 800 loans were deleted, the model would never learn that a blank is a warning sign, and the scorecard would fail when it met blanks in live applications.
The right treatment is a separate bin for missing values. It then gets its own bad rate and its own score, whatever that turns out to be. Do the same for other special codes: a utilisation of exactly zero (no revolving credit at all, a very different group from a person who has credit but uses little), a record "no bureau history", and error flags.
There is a subtlety. If missingness changes in the future, perhaps because a form is redesigned to make the field compulsory, the missing-value bin will empty out and the model will lose some of its power. This is another reason to check bin stability over time.
Categorical variables
Categorical variables, such as home ownership, product type, occupation or state, are binned by grouping their categories. The method is the same as for numbers. Start with each category, compute its bad rate, order the categories by bad rate, and merge neighbours whose rates are close and whose sizes are small. Rare categories, such as a profession with 12 applicants, should be pooled into an "other" group. Avoid grouping categories that are unrelated in meaning just because their bad rates match, since the match may be chance and the group will be hard to explain.
For categories with many levels, such as a PIN code with thousands of values, group them first by a business-meaningful key, such as city tier or region, and only then bin. Using a raw PIN code in a scorecard risks both overfitting and, in some cases, an unintended proxy for protected characteristics, a theme that returns in Lesson 5.3.
Binning in Python
A first pass takes only a few lines. Fine classing uses quantiles, and coarse classing uses edges you choose.
python
import pandas as pd
import numpy as np
df = pd.readcsv("applications.csv") # columns: utilisation, bad (1 = bad, 0 = good)
fine classing: ten equal-frequency bins
df["fine"] = pd.qcut(df["utilisation"], 10, duplicates="drop")
fine = df.groupby("fine", observed=True)["bad"].agg(loans="count", bads="sum")
fine["badrate"] = fine["bads"] / fine["loans"] 100
print(fine.round(2))
coarse classing: edges chosen after reading the fine table
edges = [-np.inf, 20, 40, 60, 80, np.inf]
labels = ["0-20", "20-40", "40-60", "60-80", "80+"]
df["coarse"] = pd.cut(df["utilisation"], edges, labels=labels, right=False)
df["coarse"] = df["coarse"].cat.addcategories("Missing").fillna("Missing")
coarse = df.groupby("coarse", observed=True)["bad"].agg(loans="count", bads="sum")
coarse["badrate"] = coarse["bads"] / coarse["loans"] 100
coarse["shareofloans"] = coarse["loans"] / coarse["loans"].sum() 100
checks: order of risk, minimum size, minimum bads
real = coarse.drop(index="Missing", errors="ignore")
print("monotonic:", real["badrate"].ismonotonicincreasing)
print("smallest bin share %:", round(coarse["shareofloans"].min(), 1))
print("fewest bads:", coarse["bads"].min())
The last three lines are the rules above turned into checks. In a working project they run after every change of the edges. Keep the bin edges, the counts and the bad rates in a table that is saved with the model, because the same edges must be applied to every future application.
A worked example: choosing between two cuttings
Return to monthly income, where the equal-width bins left only 5 bad loans in the top band. A modeller has two options. She can merge the top three bands (₹60,000 and above) into one bin of 700 + 300 + 200 = 1,200 loans with 35 + 10 + 5 = 50 bad loans, a bad rate of 50 ÷ 1,200 = 4.2 per cent. Or she can switch to quintiles, with about 200 bads per bin.
Merging the top bands fixes the worst bin: 50 bads give a margin of error of 1.96 × the square root of 0.042 × 0.958 ÷ 1,200 = about 1.1 points. It keeps edges at round numbers. But the other bins stay uneven, with 4,200 loans in the lowest band and only 1,500 in the third.
Quintiles make every bin the same size and give each about the same precision. Their edges are less tidy, and the bins may need rounding.
A practical choice is to start with quintiles or deciles to see the shape, then round the edges to nearby memorable numbers, and test the result against the rules. Either route ends in bins that satisfy the size, bads and monotonic rules. What is not acceptable is to leave the top band as it was.
Common mistakes
Equal-width bins on skewed data. The tail bins are tiny and noisy. Use quantiles first.
Too many bins. Each extra bin adds noise. If neighbours do not differ, merge them.
Ignoring bad counts. A bin of 2,000 loans with 8 bads is not reliable. Count bads, not only loans.
Forcing a monotonic shape on a variable that is not. If the real pattern is a U, explain it, or choose a different variable.
Filling blanks with the mean. Give missing values their own bin.
Binning on the whole sample and testing on the same sample. Keep a holdout to check the bins hold.
Changing edges between development and production. The same edges must be used for every future application.
Binning without looking at stability. A bin that moves in size from year to year weakens the model.
Key takeaways
Scorecards bin variables to handle non-linear effects, outliers and missing values, to keep scores explainable and to make the model stable.
Equal-width bins misbehave on skewed data, quantile bins give steady precision, business bins aid explanation, and optimal bins search for the best separation under constraints.
Fine classing shows the shape, and coarse classing merges neighbours into a few bins. In the utilisation example ten fine bins became five coarse ones with risk rising from 4.50 to 17.75 per cent.
Good bins are large, hold enough bad loans, differ from their neighbours, follow a sensible order, are stable over time and make business sense.
Missing values get their own bin. In the example the blanks had a 16 per cent bad rate against 10 per cent overall, which filling with the average would have hidden.
Check every rule in code and save the edges with the model.
Check yourself
1. A bin has 400 loans and 12 bad loans. What is its bad rate, and is it large enough by the 30-bads rule?
12 ÷ 400 = 3.0 per cent. With only 12 bads it falls short of the 30-bads rule, so it should be merged with a neighbour or given more data.
2. Two neighbouring bins have bad rates of 9.0 and 9.4 per cent, each with 1,500 loans. Should they be kept apart?
Probably not. The gap of 0.4 points is far smaller than the noise of about 1 point for each, so the z-score is well below 2. Merge them.
3. Why are equal-width bins a poor first choice for income?
Income is skewed, so equal slices leave a few very full bins at the bottom and tiny bins at the top, with too few bad loans to measure a bad rate reliably.
4. A field is blank for 6 per cent of applicants and those applicants have a bad rate of 15 per cent against 10 per cent overall. What should be done with them?
Give them a separate missing-value bin so the model can learn the extra risk. Do not delete them or replace the blanks with an average.
5. A bad rate across five bins reads 4, 7, 6, 11, 16 per cent. What would you check before merging bins 2 and 3?
Check the sizes and bad counts of the two bins and the z-score of their gap. The dip from 7 to 6 is likely noise, so merging is reasonable if the z-score is below about 2.
Try this
Bin a variable of your own from start to finish. Set aside forty to forty-five minutes.
1. Invent or download a dataset of at least 5,000 loans with a numeric variable such as age, income or utilisation and a bad flag. Make the overall bad rate about 8 to 12 per cent and give about 5 per cent of the variable missing, with a higher bad rate.
2. Make ten equal-frequency fine bins. Tabulate loans, bads and bad rate. Chart the bad rates.
3. Spot any bins that break the order of risk or hold few bads. Use the neighbour test to decide which to merge.
4. Choose four to six coarse bins with rounded edges. Add a separate bin for missing values.
5. Check every rule: each bin's share of loans, its number of bads, the order of risk and the z-score between neighbours. Write down any rule that is not met and why you accept it.
6. Use the precision simulator to find the margin of error of your smallest bin. Write it next to the bin's bad rate.
7. Write a four-sentence note for a model reviewer explaining the shape of the relationship, the bins you chose, the treatment of missing values and the one rule you would revisit with more data.
A good result is a table of coarse bins with loans, bads and bad rates, a chart showing a clean pattern, and a note showing that each rule was checked. Lesson 5.2 turns those bad rates into weight of evidence, the number that goes into the model.
Tags: Credit Risk Analytics Binning Scorecard Coarse Classing Data Preparation