compactCreditScorecard
Object Workflow
This example shows a workflow for creating a compactCreditScorecard
object from a creditscorecard
object.
Step 1. Create a creditscorecard
object
To create a compactCreditScorecard
object, you must first create a creditscorecard
object. Create a creditscorecard
object with the CreditCardData.mat
file, and set the name-value pair argument 'BinMissingData'
to true
because the dataMissing
data set contains missing data.
load CreditCardData.mat sc = creditscorecard(dataMissing,'IDVar','CustID','BinMissingData',true); sc = autobinning(sc); sc = modifybins(sc,'CustAge','MinValue',0); sc = modifybins(sc,'CustIncome','MinValue',0);
Step 2. Fit a logistic regression model for the creditscorecard
object
Use fitmodel
to fit a logistic regression model using the Weight of Evidence (WOE) data.
[sc, mdl] = fitmodel(sc);
1. Adding CustIncome, Deviance = 1490.8527, Chi2Stat = 32.588614, PValue = 1.1387992e-08 2. Adding TmWBank, Deviance = 1467.1415, Chi2Stat = 23.711203, PValue = 1.1192909e-06 3. Adding AMBalance, Deviance = 1455.5715, Chi2Stat = 11.569967, PValue = 0.00067025601 4. Adding EmpStatus, Deviance = 1447.3451, Chi2Stat = 8.2264038, PValue = 0.0041285257 5. Adding CustAge, Deviance = 1442.8477, Chi2Stat = 4.4974731, PValue = 0.033944979 6. Adding ResStatus, Deviance = 1438.9783, Chi2Stat = 3.86941, PValue = 0.049173805 7. Adding OtherCC, Deviance = 1434.9751, Chi2Stat = 4.0031966, PValue = 0.045414057 Generalized linear regression model: logit(status) ~ 1 + CustAge + ResStatus + EmpStatus + CustIncome + TmWBank + OtherCC + AMBalance Distribution = Binomial Estimated Coefficients: Estimate SE tStat pValue ________ ________ ______ __________ (Intercept) 0.70229 0.063959 10.98 4.7498e-28 CustAge 0.57421 0.25708 2.2335 0.025513 ResStatus 1.3629 0.66952 2.0356 0.04179 EmpStatus 0.88373 0.2929 3.0172 0.002551 CustIncome 0.73535 0.2159 3.406 0.00065929 TmWBank 1.1065 0.23267 4.7556 1.9783e-06 OtherCC 1.0648 0.52826 2.0156 0.043841 AMBalance 1.0446 0.32197 3.2443 0.0011775 1200 observations, 1192 error degrees of freedom Dispersion: 1 Chi^2-statistic vs. constant model: 88.5, p-value = 2.55e-16
Step 3. Create a new data set for scoring the creditscorecard
object
Create a new data set that is used for scoring based on the previously created creditscorecard
object.
tdata = data(1:10, mdl.PredictorNames); tdata.CustAge(2) = NaN; tdata.CustAge(5) = -5; tdata.ResStatus(1) = missing; tdata.ResStatus(3) = 'Landlord'; tdata.EmpStatus(3) = missing; tdata.CustIncome(4) = NaN; tdata.EmpStatus(7) = 'Freelancer'; tdata.CustIncome(8) = -1; tdata.CustIncome(4) = NaN; disp(tdata);
CustAge ResStatus EmpStatus CustIncome TmWBank OtherCC AMBalance _______ ___________ ___________ __________ _______ _______ _________ 53 <undefined> Unknown 50000 55 Yes 1055.9 NaN Home Owner Employed 52000 25 Yes 1161.6 47 Landlord <undefined> 37000 61 No 877.23 50 Home Owner Employed NaN 20 Yes 157.37 -5 Home Owner Employed 53000 14 Yes 561.84 65 Home Owner Employed 48000 59 Yes 968.18 34 Home Owner Freelancer 32000 26 Yes 717.82 50 Other Employed -1 33 No 3041.2 50 Tenant Unknown 52000 25 Yes 115.56 49 Home Owner Unknown 53000 23 Yes 718.5
Use displaypoints
to display the points per predictor. Use score
to compute the credit scores using the new data (tdata
). Then use probdefault
with the new data (tdata
) to calculate probability of default. When using formatpoints
, the 'Missing'
name-value pair argument is set to 'minpoints'
because tdata
contains missing data.
PointsInfo = displaypoints(sc)
PointsInfo=38×3 table
Predictors Bin Points
_____________ ______________ _________
{'CustAge' } {'[0,33)' } -0.14173
{'CustAge' } {'[33,37)' } -0.11095
{'CustAge' } {'[37,40)' } -0.059244
{'CustAge' } {'[40,46)' } 0.074167
{'CustAge' } {'[46,48)' } 0.1889
{'CustAge' } {'[48,51)' } 0.20204
{'CustAge' } {'[51,58)' } 0.22935
{'CustAge' } {'[58,Inf]' } 0.45019
{'CustAge' } {'<missing>' } 0.0096749
{'ResStatus'} {'Tenant' } -0.029778
{'ResStatus'} {'Home Owner'} 0.12425
{'ResStatus'} {'Other' } 0.36796
{'ResStatus'} {'<missing>' } 0.1364
{'EmpStatus'} {'Unknown' } -0.075948
{'EmpStatus'} {'Employed' } 0.31401
{'EmpStatus'} {'<missing>' } NaN
⋮
[Scores, Points] = score(sc, tdata)
Scores = 10×1
1.2784
1.0071
NaN
NaN
0.9960
1.8771
NaN
NaN
1.0283
0.8095
Points=10×7 table
CustAge ResStatus EmpStatus CustIncome TmWBank OtherCC AMBalance
_________ _________ _________ __________ _________ ________ _________
0.22935 0.1364 -0.075948 0.45309 0.3958 0.15715 -0.017438
0.0096749 0.12425 0.31401 0.45309 -0.033652 0.15715 -0.017438
0.1889 0.1364 NaN 0.080697 0.3958 -0.18537 -0.017438
0.20204 0.12425 0.31401 NaN -0.044701 0.15715 0.35539
0.0096749 0.12425 0.31401 0.45309 -0.044701 0.15715 -0.017438
0.45019 0.12425 0.31401 0.45309 0.3958 0.15715 -0.017438
-0.11095 0.12425 NaN -0.11452 -0.033652 0.15715 -0.017438
0.20204 0.36796 0.31401 NaN -0.033652 -0.18537 -0.21195
0.20204 -0.029778 -0.075948 0.45309 -0.033652 0.15715 0.35539
0.20204 0.12425 -0.075948 0.45309 -0.033652 0.15715 -0.017438
pd = probdefault(sc, tdata)
pd = 10×1
0.2178
0.2676
NaN
NaN
0.2697
0.1327
NaN
NaN
0.2634
0.3080
sc = formatpoints(sc,'BasePoints',true,'Missing','minpoints','Round','finalscore','PointsOddsAndPDO',[500, 2, 50]); PointsInfo1 = displaypoints(sc)
PointsInfo1=39×3 table
Predictors Bin Points
______________ ______________ _______
{'BasePoints'} {'BasePoints'} 500.66
{'CustAge' } {'[0,33)' } -17.461
{'CustAge' } {'[33,37)' } -15.24
{'CustAge' } {'[37,40)' } -11.511
{'CustAge' } {'[40,46)' } -1.8871
{'CustAge' } {'[46,48)' } 6.3888
{'CustAge' } {'[48,51)' } 7.3367
{'CustAge' } {'[51,58)' } 9.3068
{'CustAge' } {'[58,Inf]' } 25.238
{'CustAge' } {'<missing>' } -6.5392
{'ResStatus' } {'Tenant' } -9.3852
{'ResStatus' } {'Home Owner'} 1.7253
{'ResStatus' } {'Other' } 19.305
{'ResStatus' } {'<missing>' } 2.6022
{'EmpStatus' } {'Unknown' } -12.716
{'EmpStatus' } {'Employed' } 15.414
⋮
[Scores1, Points1] = score(sc, tdata)
Scores1 = 10×1
542
523
488
495
522
585
445
448
524
508
Points1=10×8 table
BasePoints CustAge ResStatus EmpStatus CustIncome TmWBank OtherCC AMBalance
__________ _______ _________ _________ __________ _______ _______ _________
500.66 9.3068 2.6022 -12.716 25.446 21.314 4.0988 -8.495
500.66 -6.5392 1.7253 15.414 25.446 -9.6646 4.0988 -8.495
500.66 6.3888 2.6022 -12.716 -1.4161 21.314 -20.609 -8.495
500.66 7.3367 1.7253 15.414 -42.148 -10.462 4.0988 18.399
500.66 -6.5392 1.7253 15.414 25.446 -10.462 4.0988 -8.495
500.66 25.238 1.7253 15.414 25.446 21.314 4.0988 -8.495
500.66 -15.24 1.7253 -12.716 -15.498 -9.6646 4.0988 -8.495
500.66 7.3367 19.305 15.414 -42.148 -9.6646 -20.609 -22.526
500.66 7.3367 -9.3852 -12.716 25.446 -9.6646 4.0988 18.399
500.66 7.3367 1.7253 -12.716 25.446 -9.6646 4.0988 -8.495
pd1 = probdefault(sc, tdata)
pd1 = 10×1
0.2178
0.2676
0.3721
0.3488
0.2697
0.1327
0.5178
0.5077
0.2634
0.3080
Step 4. Create a compactCreditScorecard
object from the creditscorecard
object
Create a compactCreditScorecard
object using the creditscorecard
object as the input. Alternatively, you can create the compactCreditScorecard
object using the compact
function in Financial Toolbox™.
csc = compactCreditScorecard(sc)
csc = compactCreditScorecard with properties: Description: '' GoodLabel: 0 ResponseVar: 'status' WeightsVar: '' NumericPredictors: {'CustAge' 'CustIncome' 'TmWBank' 'AMBalance'} CategoricalPredictors: {'ResStatus' 'EmpStatus' 'OtherCC'} PredictorVars: {'CustAge' 'ResStatus' 'EmpStatus' 'CustIncome' 'TmWBank' 'OtherCC' 'AMBalance'}
Step 5. Use associated functions to analyze the compactCreditScorecard
object
You can analyze the compactCreditScorecard object with displaypoints
, score
, and probdefault
from Risk Management Toolbox™.
PointsInfo2 = displaypoints(csc)
PointsInfo2=39×3 table
Predictors Bin Points
______________ ______________ _______
{'BasePoints'} {'BasePoints'} 500.66
{'CustAge' } {'[0,33)' } -17.461
{'CustAge' } {'[33,37)' } -15.24
{'CustAge' } {'[37,40)' } -11.511
{'CustAge' } {'[40,46)' } -1.8871
{'CustAge' } {'[46,48)' } 6.3888
{'CustAge' } {'[48,51)' } 7.3367
{'CustAge' } {'[51,58)' } 9.3068
{'CustAge' } {'[58,Inf]' } 25.238
{'CustAge' } {'<missing>' } -6.5392
{'ResStatus' } {'Tenant' } -9.3852
{'ResStatus' } {'Home Owner'} 1.7253
{'ResStatus' } {'Other' } 19.305
{'ResStatus' } {'<missing>' } 2.6022
{'EmpStatus' } {'Unknown' } -12.716
{'EmpStatus' } {'Employed' } 15.414
⋮
[Scores2, Points2] = score(csc, tdata)
Scores2 = 10×1
542
523
488
495
522
585
445
448
524
508
Points2=10×8 table
BasePoints CustAge ResStatus EmpStatus CustIncome TmWBank OtherCC AMBalance
__________ _______ _________ _________ __________ _______ _______ _________
500.66 9.3068 2.6022 -12.716 25.446 21.314 4.0988 -8.495
500.66 -6.5392 1.7253 15.414 25.446 -9.6646 4.0988 -8.495
500.66 6.3888 2.6022 -12.716 -1.4161 21.314 -20.609 -8.495
500.66 7.3367 1.7253 15.414 -42.148 -10.462 4.0988 18.399
500.66 -6.5392 1.7253 15.414 25.446 -10.462 4.0988 -8.495
500.66 25.238 1.7253 15.414 25.446 21.314 4.0988 -8.495
500.66 -15.24 1.7253 -12.716 -15.498 -9.6646 4.0988 -8.495
500.66 7.3367 19.305 15.414 -42.148 -9.6646 -20.609 -22.526
500.66 7.3367 -9.3852 -12.716 25.446 -9.6646 4.0988 18.399
500.66 7.3367 1.7253 -12.716 25.446 -9.6646 4.0988 -8.495
pd2 = probdefault(csc, tdata)
pd2 = 10×1
0.2178
0.2676
0.3721
0.3488
0.2697
0.1327
0.5178
0.5077
0.2634
0.3080
Compare the size of the creditscorecard
and compactCreditScorecard
objects.
whos('dataMissing','sc','csc')
Name Size Bytes Class Attributes csc 1x1 41509 compactCreditScorecard dataMissing 1200x11 85035 table sc 1x1 167007 creditscorecard
The size of the compactCreditScorecard
object is lightweight compared to the creditscorecard
object. However, the compactCreditScorecard
object cannot be directly modified. If you need to change a compactCreditScorecard
object, you must change the starting creditscorecard
object, and then reconvert that object to create the compactCreditScorecard
object again.
See Also
creditscorecard
| screenpredictors
| autobinning
| bininfo
| predictorinfo
| modifypredictor
| modifybins
| bindata
| plotbins
| fitmodel
| displaypoints
| formatpoints
| score
| setmodel
| probdefault
| validatemodel
Related Examples
- Common Binning Explorer Tasks
- Credit Scorecard Modeling with Missing Values
- Feature Screening with screenpredictors
- Troubleshooting Credit Scorecard Results
- Credit Rating by Bagging Decision Trees
- Stress Testing of Consumer Credit Default Probabilities Using Panel Data
More About
- Overview of Binning Explorer
- About Credit Scorecards
- Credit Scorecard Modeling Workflow
- Monotone Adjacent Pooling Algorithm (MAPA)
- Credit Scorecard Modeling Using Observation Weights