discardResiduals
Description
Examples
This example shows how to create a Cox model and then use discardResiduals to remove residual information to reduce the model's memory usage.
Load Data
Load the credit portfolio data.
load RetailCreditPanelData.mat
disp(head(data)) ID ScoreGroup YOB Default Year
__ __________ ___ _______ ____
1 Low Risk 1 0 1997
1 Low Risk 2 0 1998
1 Low Risk 3 0 1999
1 Low Risk 4 0 2000
1 Low Risk 5 0 2001
1 Low Risk 6 0 2002
1 Low Risk 7 0 2003
1 Low Risk 8 0 2004
disp(head(dataMacro))
Year GDP Market
____ _____ ______
1997 2.72 7.61
1998 3.57 26.24
1999 2.86 18.1
2000 2.43 3.19
2001 1.26 -10.51
2002 -0.59 -22.95
2003 0.63 2.78
2004 1.85 9.48
Join the Data
Join the two data components into a single data set.
data = join(data,dataMacro); disp(head(data))
ID ScoreGroup YOB Default Year GDP Market
__ __________ ___ _______ ____ _____ ______
1 Low Risk 1 0 1997 2.72 7.61
1 Low Risk 2 0 1998 3.57 26.24
1 Low Risk 3 0 1999 2.86 18.1
1 Low Risk 4 0 2000 2.43 3.19
1 Low Risk 5 0 2001 1.26 -10.51
1 Low Risk 6 0 2002 -0.59 -22.95
1 Low Risk 7 0 2003 0.63 2.78
1 Low Risk 8 0 2004 1.85 9.48
Partition the Data
Separate the data into training and test partitions.
nIDs = max(data.ID); uniqueIDs = unique(data.ID); rng('default'); % for reproducibility c = cvpartition(nIDs,'HoldOut',0.4); TrainIDInd = training(c); TestIDInd = test(c); TrainDataInd = ismember(data.ID,uniqueIDs(TrainIDInd)); TestDataInd = ismember(data.ID,uniqueIDs(TestIDInd));
Create a Cox Lifetime PD Model
Use fitLifetimePDModel to create a Cox model.
pdModel = fitLifetimePDModel(data(TrainDataInd,:),"Cox",... IDVar="ID", AgeVar="YOB", LoanVars="ScoreGroup", ... MacroVars={'GDP','Market'}, ResponseVar="Default"); disp(pdModel)
Cox with properties:
ExtrapolationFactor: 1
ModelID: "Cox"
Description: ""
UnderlyingModel: [1×1 CoxModel]
IDVar: "ID"
AgeVar: "YOB"
LoanVars: "ScoreGroup"
MacroVars: ["GDP" "Market"]
ResponseVar: "Default"
WeightsVar: ""
TimeInterval: 1
The Cox pdModel object uses a noticeable amount of memory.
whos pdModelName Size Bytes Class Attributes pdModel 1x1 59001617 risk.credit.pd.Cox
This is because the underlying Cox model stores residual information, and multiple residual types are supported.
head(pdModel.UnderlyingModel.Residuals)
CoxSnell Deviance Martingale Schoenfeld ScaledSchoenfeld Score ScaledScore
_________ ________ __________ ________________________ ________________________ ________________ ________________
0.0092625 0 0 NaN NaN NaN NaN NaN NaN NaN NaN 0 0 0 0 0 0 0 0
0.012537 0 0 NaN NaN NaN NaN NaN NaN NaN NaN 0 0 0 0 0 0 0 0
0.018878 0 0 NaN NaN NaN NaN NaN NaN NaN NaN 0 0 0 0 0 0 0 0
0.026346 0 0 NaN NaN NaN NaN NaN NaN NaN NaN 0 0 0 0 0 0 0 0
0.036303 0 0 NaN NaN NaN NaN NaN NaN NaN NaN 0 0 0 0 0 0 0 0
0.051269 0 0 NaN NaN NaN NaN NaN NaN NaN NaN 0 0 0 0 0 0 0 0
0.038922 0 0 NaN NaN NaN NaN NaN NaN NaN NaN 0 0 0 0 0 0 0 0
0.034104 0 0 NaN NaN NaN NaN NaN NaN NaN NaN 0 0 0 0 0 0 0 0
For additional information on the residuals, see CoxModel.
Remove Residual Information
For prediction purposes, the residual information can be discarded using discardResiduals without affecting the prediction or validation functionality of the Cox lifetime PD model.
pdModel = discardResiduals(pdModel)
pdModel =
Cox with properties:
ExtrapolationFactor: 1
ModelID: "Cox"
Description: ""
UnderlyingModel: [1×1 CoxModel]
IDVar: "ID"
AgeVar: "YOB"
LoanVars: "ScoreGroup"
MacroVars: ["GDP" "Market"]
ResponseVar: "Default"
WeightsVar: ""
TimeInterval: 1
The model storage is minimal once the residuals have been discarded and the Residuals property of the underlying model have been emptied.
whos pdModelName Size Bytes Class Attributes pdModel 1x1 9305 risk.credit.pd.Cox
pdModel.UnderlyingModel.Residuals
ans =
0×1 empty table
Var1
____
The prediction and validation functions are not affected after the residuals have been discarded.
pdLifetime = predictLifetime(pdModel,data(1:8,:))
pdLifetime = 8×1
0.0092
0.0143
0.0189
0.0229
0.0265
0.0305
0.0321
0.0330
modelCalibrationPlot(pdModel,data(TrainDataInd,:),'Year')
Copyright 2022 The MathWorks, Inc.
Input Arguments
Probability of default model, specified as a previously created Cox object using
fitLifetimePDModel.
Data Types: object
Output Arguments
Updated Cox PD model, returned as a Cox model.
Version History
Introduced in R2023a
See Also
modelCalibration | modelDiscrimination | modelDiscriminationPlot | modelCalibrationPlot | predictLifetime | fitLifetimePDModel | Cox | customLifetimePDModel
Topics
- Basic Lifetime PD Model Validation
- Compare Logistic Model for Lifetime PD to Champion Model
- Compare Lifetime PD Models Using Cross-Validation
- Expected Credit Loss Computation
- Compare Model Discrimination and Model Calibration to Validate of Probability of Default
- Compare Probability of Default Using Through-the-Cycle and Point-in-Time Models
- Overview of Lifetime Probability of Default Models
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)