GRADBOOST Procedure
Example 17.4 Mitigating Bias of a Boosting Tree Model
This example uses the GRADBOOST procedure to create a gradient boosting tree model while minimizing the demographic parity for the Job variable. The response variable for the gradient boosting tree model is Bad, a classification variable that has two values (0 for payment of loan and 1 for default). The other variables are predictor variables for the model.
The following statements load the data table mylib.hmeq into your CAS session. For this example, the statements assume that your CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.
data mylib.hmeq;
set sampsio.hmeq;
run;
The following statements use PROC GRADBOOST to create a gradient boosting tree model without minimizing the demographic parity:
proc gradboost data=mylib.hmeq nTrees=20 seed=12345;
input CLAge CLNo DebtInc Derog
Loan MortDue Value / level=interval;
input Reason / level=nominal;
target Bad / level=nominal;
output out=mylib.scored copyvars=(_ALL_);
saveState rstore=mylib.model;
run;
The NTREES= option specifies that there are 20 trees to grow in the boosting model. The SEED= option specifies the random number seed for model building to be 12345. The two INPUT statements specify CLAge, CLNo, DebtInc, Derog, Loan, MortDue, Value, and Reason as the input variables. The TARGET statement specifies Bad as the target variable. The OUTPUT statement generates the data table mylib.scored, which contains the predicted mortgage default from the model for each observation and contains all variables from the input data table as copy variables. The SAVESTATE statement creates an analytic store for the model and saves it as a binary object in the data table mylib.model.
Output 17.4.1 displays the fit statistics for the boosting model.
Output 17.4.1: Fit Statistics Table
| Fit Statistics | |||
|---|---|---|---|
| Number of Trees | Training Average Square Error | Training Misclassification Rate | Training Log Loss |
| 1 | 0.1464 | 0.199 | 0.461 |
| 2 | 0.1359 | 0.199 | 0.432 |
| 3 | 0.1272 | 0.199 | 0.410 |
| 4 | 0.1202 | 0.199 | 0.392 |
| 5 | 0.1143 | 0.193 | 0.377 |
| 6 | 0.1095 | 0.175 | 0.364 |
| 7 | 0.1054 | 0.162 | 0.353 |
| 8 | 0.1021 | 0.156 | 0.344 |
| 9 | 0.0992 | 0.137 | 0.336 |
| 10 | 0.0966 | 0.128 | 0.329 |
| 11 | 0.0943 | 0.123 | 0.322 |
| 12 | 0.0925 | 0.116 | 0.317 |
| 13 | 0.0908 | 0.114 | 0.312 |
| 14 | 0.0896 | 0.113 | 0.308 |
| 15 | 0.0885 | 0.114 | 0.304 |
| 16 | 0.0872 | 0.113 | 0.300 |
| 17 | 0.0864 | 0.113 | 0.297 |
| 18 | 0.0857 | 0.113 | 0.294 |
| 19 | 0.0849 | 0.113 | 0.291 |
| 20 | 0.0842 | 0.112 | 0.289 |
After you train a gradient boosting tree model, you might want to view the demographic parity of the trained model. You can do this by running the ASSESSBIAS procedure. For more information about PROC ASSESSBIAS, see Chapter 3, ASSESSBIAS Procedure.
The following statements use PROC ASSESSBIAS to assess the bias measurements of the model:
proc assessbias data=mylib.scored;
target bad / event="1" level=nominal;
var P_Bad1;
fitstat pvar=P_BAD0 / pevent="0";
sensitiveVar Job;
run;
Output 17.4.2 displays the bias metric values of the model. PROC ASSESSBIAS also produces other output not shown here.
Output 17.4.2: Bias Metrics Table
| Bias Metrics | |||||
|---|---|---|---|---|---|
| Bias Statistic | Bias Statistic Label | Bias Statistic Value | Base Level | Compare Level | Note |
| DemographicParity | Demographic Parity (Statistical Parity) | 0.1170 | Self | Office | |
| PredictiveParity | Predictive Parity | 0.0836 | Sales | Office | |
| EqualAccuracy | Equal Accuracy | 0.1090 | Office | Sales | |
| EqualizedOdds | Equalized Odds | 0.1806 | Self | Sales | The maximum TPR difference is greater than the maximum FPR difference. |
| EqualOpportunity | Equal Opportunity | 0.1806 | Self | Sales | |
In order to use the MITIGATEBIAS statement to reduce the demographic parity, you must specify the levels of the response (target) variable and the corresponding predicted variables. You can use the DESCRIBE statement in the ASTORE procedure to obtain this information. The following statements use PROC ASTORE to describe the model:
proc astore;
describe rstore=mylib.model;
run;
Output 17.4.3 lists the output variables created by the model. The predicted variables are P_BAD1 and P_BAD0. Their corresponding response (target) levels are 1 and 0, respectively.
Output 17.4.3: Output Variables Table
| Output Variables | |||
|---|---|---|---|
| Name | Length | Type | Label |
| P_BAD1 | 8 | Num | Predicted: BAD=1 |
| P_BAD0 | 8 | Num | Predicted: BAD=0 |
| I_BAD | 12 | Character | Into: BAD |
| _WARN_ | 4 | Character | Warnings |
The following statements use PROC GRADBOOST to create a gradient boosting tree model, while minimizing the demographic parity for Job by using the MITIGATEBIAS statement:
ods graphics on;
proc gradboost data=mylib.hmeq nTrees=20 seed=12345;;
input CLAge CLNo DebtInc Derog
Loan MortDue Value / level=interval;
input Reason / level=nominal;
target Bad / level=nominal;
output out=mylib.scored;
saveState rstore=mylib.model;
mitigateBias pevents="1 0"
pvars=(P_BAD1 P_BAD0)
seed=12345
sensitivevar=Job
targetEvent="1"
maxiter=11;
run;
The PEVENTS= option lists the levels of the response (target) variable Bad. The predicted variables correspond to the levels that are listed in the PVARS= option. The PVARS= option lists the predicted variables that contain the posterior probability for each level in model prediction that corresponds to the response (target) variable Bad. The SEED= option specifies the seed for the pseudorandom number generator to be 12345. The SENSITIVEVAR= option names the variable Job as the sensitive variable for the purpose of reducing the value of the bias measurement. The TARGETEVENT= option specifies the value 1 as the event of interest. The MAXITER= option specifies 11 as the maximum number of iterations for the EGR algorithm.
Output 17.4.4 displays the information about the options that are used for bias mitigation. Output 17.4.5 displays the model accuracy and bias metric values over each iteration of the EGR algorithm. Output 17.4.6 shows the iteration history, which is a graphical representation of the iteration history table. The graph displays the bias metric and the misclassification rate for each iteration. PROC GRADBOOST selects the iteration that has the lowest bias metric. In this case, the 10th iteration is selected; the graph indicates this selection by using the legend and a vertical line. The MITIGATEBIAS statement also creates other tables, which are not shown here but are listed in the section ODS Table Names.
Output 17.4.4: Mitigation Information Table
| Mitigation Information | ||
|---|---|---|
| Description | Character Value | Value |
| Bias Metric | DEMOGRAPHICPARITY | . |
| Sensitive Variable | JOB | . |
| Response | BAD | . |
| Bound Value | 100 | 100 |
| Learning Rate | 0.01 | 0.01 |
| Maximum Iteration | 11 | 11 |
| Tolerance | 0.005 | 0.005 |
| Event Level | 1 | . |
Output 17.4.5: Iteration History Table
| EGR Iteration History | |||
|---|---|---|---|
| Iteration | Demographic Parity (Statistical Parity) | Misclassification Rate | Multi-Class Log Loss |
| 1 | 0.117034 | 0.1124 | 0.2887 |
| 2 | 0.100985 | 0.1136 | 0.2896 |
| 3 | 0.109836 | 0.1154 | 0.2901 |
| 4 | 0.105709 | 0.1144 | 0.2895 |
| 5 | 0.096401 | 0.1154 | 0.2902 |
| 6 | 0.100621 | 0.1148 | 0.2906 |
| 7 | 0.085066 | 0.1141 | 0.2917 |
| 8 | 0.098604 | 0.1148 | 0.2927 |
| 9 | 0.072697 | 0.1168 | 0.2933 |
| 10 | 0.064812 | 0.1164 | 0.2940 |
| 11 | 0.072883 | 0.1158 | 0.2937 |
Output 17.4.6: Iteration History Graph
