Risk Modeling and Decisioning Action Set
Fit a Credit Scoring Model
This section contains PROC CAS code.
Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 2, Shared Concepts (SAS Viya: Machine Learning Procedures). A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.
This example shows how to use the optBinning action to fit a credit scoring model. In this example, the input data set datain contains information about fine bins. The parameter data set parms contains the constraints.
The following data set, datain, includes the bin number, number of bad observations, number of good observations, weight of evidence (WOE), variable name, lower bound, upper bound, and WOE trend:
data datain;
input bin varB varG WOE display_var $8.
low high woeTrend ;
datalines;
1 106 32 -1.197703191 AGE 18 21 -0.920258863
2 54 24 -0.810930216 AGE 21 22 -0.739566193
3 94 28 -1.211090272 AGE 22 23 -0.679335303
4 93 46 -0.703958097 AGE 23 24 -0.619104414
5 170 103 -0.501069449 AGE 24 25.5 -0.558873524
1 3 7 0.8472978604 CASH 0 500 -0.175718155
2 89 72 -0.211970251 CASH 500 600 -0.129804828
3 88 54 -0.488352768 CASH 600 700 -0.120622163
4 82 70 -0.158224005 CASH 700 800 -0.111439498
5 78 82 0.0500104206 CASH 800 900 -0.102256832
6 81 67 -0.189756535 CASH 900 1000 -0.093074167
7 104 99 -0.049271049 CASH 1000 1100 -0.083891502
8 62 51 -0.195308752 CASH 1100 1200 -0.074708837
9 60 77 0.2494608596 CASH 1200 1300 -0.065526171
1 241 466 0.6593887006 INCOME 0 1000 0.2774569026
2 39 24 -0.485507816 INCOME 1000 1500 0.1286536432
3 156 95 -0.495979116 INCOME 1500 1700 0.0542520135
4 122 55 -0.79668786 INCOME 1700 1900 0.0244913616
5 54 41 -0.27541198 INCOME 1900 2000 -0.00526929
6 99 60 -0.500775288 INCOME 2000 2100 -0.020149616
7 47 28 -0.517943092 INCOME 2100 2200 -0.035029942
8 98 54 -0.595983432 INCOME 2200 2300 -0.049910268
9 131 102 -0.25022451 INCOME 2300 2500 -0.064790594
10 142 129 -0.096014653 INCOME 2500 2700 -0.094551246
11 109 107 -0.018519048 INCOME 2700 3000 -0.124311898
12 119 162 0.3084728421 INCOME 3000 3400 -0.168952876
13 46 74 0.4754236967 INCOME 3400 4000 -0.228474179
;
In the following parameter data set, parms, each row contains the constraints for each characteristic variable. The columns contain different constraints for each variable. If an upper bound value for a constraint is 0, the constraint is treated as not bounded above.
data parms;
input display_var $8. MinBinDiff MinBinWidth
MaxBinWidth woeTrend minBinG
minBinB minBinTol maxBinTol minNumBin
maxNumBin;
datalines;
AGE 0.01 0 0 1 1 1 150 23250 2 5
CASH 0.01 0 0 1 1 1 150 23250 2 5
INCOME 0.01 0 0 1 1 1 150 23250 2 5
;
You can load datain and parms into your CAS session by naming your CAS engine libref in the first statement of the following DATA steps:
data mycas.datain;
set datain;
run;
data mycas.parms;
set parms;
run;
This statement assumes that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.
The following statements run optBinning action and output the results, the out and stat data tables, to the mycas CAS library engine:
proc cas;
loadactionset "riskmd";
action optBinning /
data={name="datain"}
param={name="parms"}
output={name="out" replace=True}
status={name="stat" replace=True}
adjustFactor=0.2
;
run;
The following statements display the mycas.out and mycas.stat tables shown in Output 34.1.1 and Output 34.1.2.
proc print data=mycas.out; run;
proc print data=mycas.stat; run;
Output 34.1.1: Output
| Obs | DISPLAY_VAR | LOW | HIGH | WOE |
|---|---|---|---|---|
| 1 | AGE | 18 | 23.0 | -0.30951 |
| 2 | AGE | 23 | 25.5 | 0.22880 |
| 3 | CASH | 0 | 800.0 | -0.14409 |
| 4 | CASH | 800 | 1100.0 | 0.05232 |
| 5 | CASH | 1100 | 1300.0 | 0.15905 |
| 6 | INCOME | 0 | 1000.0 | 0.66367 |
| 7 | INCOME | 1000 | 4000.0 | -0.21735 |
In Output 34.1.1, the observations are grouped by variable names. Within each group, each observation shows the lower bound, upper bound, and WOE of a coarse bin.
Output 34.1.2: Status
| Obs | DISPLAY_VAR | STATUS |
|---|---|---|
| 1 | AGE | OPTIMAL |
| 2 | CASH | OPTIMAL |
| 3 | INCOME | OPTIMAL |
In Output 34.1.2, each observation shows the solution status on each characteristic variable. When all the constraints on a variable are satisfied, the status is OPTIMAL. If any constraint is violated, the status is INFEASIBLE.
Fit a Credit Scoring Model
This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the datain data to the comma-separated-value (CSV) file datain.csv, convert the parms data to the CSV file parms.csv, and then use the following code to load the CSV files into CAS:
s:loadtable{casLib="casuser", path="datain.csv"}
s:loadtable{casLib="casuser", path="parms.csv"}
For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.
This example shows how to use the optBinning action to fit a credit scoring model. In the example, the input data table datain.csv contains information about fine bins. The parameter data table param.csv contains the constraints.
The following code runs optBinning action and outputs the out and stat tables:
s:loadactionset{actionset="riskmd"}
s:riskmd_optBinning{
data={name="datain"},
param={name="parms"},
output={casout={name="out", replace=True}, standardPc=True},
status={casout={name="stat", replace=True}, standardPc=True},
adjustFactor=0.2
}
The following statements display the out and stat tables:
r = s:fetch{table={name="out"}, to=50}
print(r.Fetch)
r = s:fetch{table={name="stat"}, to=50}
print(r.Fetch)
For details about the results of this analysis, see the CASL version of this example.
Fit a Credit Scoring Model
This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the datain data to the comma-separated-value (CSV) file datain.csv, convert the parms data to the CSV file parms.csv, and then use the following code to load the CSV files into CAS:
s.upload_file('datain.csv')
s.upload_file('parms.csv')
For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
This example shows how to use the optBinning action to fit a credit scoring model. In the example, the input file datain.csv contains information about fine bins. The parameter file param.csv contains the constraints.
The following code runs optBinning action and outputs the out and stat tables:
s.loadactionset(actionset="riskmd")
s.riskmd.optBinning(
data={"name":"datain"},
param={"name":"parms"},
output={"casout":{"name":"out", "replace":True}, "standardPc":True},
status={"casout":{"name":"stats", "replace":True}, "standardPc":True},
adjustFactor=0.2
)
The following statements display the out and stat tables:
print(s.fetch(table={"name":"out"}, to=50))
print(s.fetch(table={"name":"stat"}, to=50))
For details about the results of this analysis, see the CASL version of this example.
Fit a Credit Scoring Model
This section contains R code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the datain data to the comma-separated-value (CSV) file datain.csv, convert the parms data to the CSV file parms.csv, and then use the following code to load the CSV files into CAS:
m <- cas.read.csv(s, "datain.csv", casOut=list(name="datain"))
m <- cas.read.csv(s, "parms.csv", casOut=list(name="parms"))
For more information about coding in R, see Getting Started with SAS Viya for R and SAS Viya: System Programming Guide.
This example shows how to use the optBinning action to fit a credit scoring model. In this example, the input file datain.csv contains information about fine bins. The parameter file param.csv contains the constraints.
The following code runs optBinning action and outputs out and stat tables:
loadActionSet(s,'riskmd')
m <- cas.riskmd.optBinning(s,
data =list(name="datain"),
param =list(name="parms"),
output=list(out =list(name="out",replace=TRUE)),
status=list(stat =list(name="stat",replace=TRUE)),
adjustFactor=0.2
)
The following statements display the out and stat tables.
output <- cas.table.fetch(s, table = list(name = "out"), to = 50)
print(output)
status <- cas.table.fetch(s, table = list(name = "stat"), to = 50)
print(status)
For details about the results of this analysis, see the CASL version of this example.