SVMACHINE Procedure
Example 35.6 Mitigating Bias of a Support Vector Classification
This example uses the SVMACHINE procedure to create a support vector classification model while minimizing the equal opportunity bias for the Reason variable. The response variable for the support vector classification 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 SAS library. For this example, the statements assume that your SAS library is named mylib, but you can substitute any appropriately defined SAS library.
data mylib.hmeq;
set sampsio.hmeq;
run;
The following statements use PROC SVMACHINE to create a support vector classification model without minimizing the equal opportunity bias:
proc svmachine data=mylib.hmeq c=0.1;
input clage clno debtinc loan mortdue value yoj delinq derog job ninq;
input delinq derog job ninq / level=nominal;
target bad;
output out=mylib.scored copyvars=(_ALL_);
savestate rstore=mylib.model;
run;
The C= option specifies 0.1 as the penalty for training. The two INPUT statements specify clage, clno, debtinc, loan, mortdue, value, yoj, delinq, derog, job, and ninq 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 35.6.1 displays the fit statistics for the classification model.
Output 35.6.1: Fit Statistics Table
| Fit Statistics | |
|---|---|
| Statistic | Training |
| Accuracy | 0.9156 |
| Error | 0.0844 |
| Sensitivity | 0.0584 |
| Specificity | 1.0000 |
After you train a support vector classification model, you might want to view the equal opportunity bias 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 reason;
run;
Output 35.6.2 displays the bias metric values of the model. PROC ASSESSBIAS also produces other output not shown here.
Output 35.6.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.0165 | HomeImp | ||
| PredictiveParity | Predictive Parity | 0.1373 | HomeImp | ||
| EqualAccuracy | Equal Accuracy | 0.0344 | DebtCon | HomeImp | |
| EqualizedOdds | Equalized Odds | 0.0242 | DebtCon | HomeImp | The maximum TPR difference is greater than the maximum FPR difference. |
| EqualOpportunity | Equal Opportunity | 0.0242 | DebtCon | HomeImp | |
In order to use the MITIGATEBIAS statement to reduce the equal opportunity bias, 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 35.6.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 35.6.3: Output Variables Table
| Output Variables | |||
|---|---|---|---|
| Name | Length | Type | Label |
| _P_ | 8 | Num | Decision Function |
| 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 SVMACHINE to create a support vector classification model, while minimizing the equal opportunity bias for reason by using the MITIGATEBIAS statement:
ods graphics on;
proc svmachine data=mylib.hmeq c=0.1;
input clage clno debtinc loan mortdue value yoj delinq derog job ninq;
input delinq derog job ninq / level=nominal;
target bad;
mitigatebias biasmetric=EQUALOPPORTUNITY bound=75 pevents="1 0"
pvars=(P_BAD1 P_BAD0) seed=12345 sensitivevar=reason targetevent="1";
output out=mylib.scored copyvars=(_ALL_);
savestate rstore=mylib.model;
run;
The BIASMETRIC= option specifies that equal opportunity be used as the bias metric. The BOUND= option specifies 75 as the bound value for the EGR algorithm. 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 reason 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.
Output 35.6.4 displays the information about the options that are used for bias mitigation. Output 35.6.5 displays the model accuracy and bias metric values over each iteration of the EGR algorithm. Output 35.6.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 SVMACHINE selects the iteration that has the lowest bias metric. In this case, the 8th 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 35.6.4: Mitigation Information Table
| Mitigation Information | ||
|---|---|---|
| Description | Character Value | Value |
| Bias Metric | EQUALOPPORTUNITY | . |
| Sensitive Variable | REASON | . |
| Response | BAD | . |
| Bound Value | 75 | 75 |
| Learning Rate | 0.01 | 0.01 |
| Maximum Iteration | 10 | 10 |
| Tolerance | 0.005 | 0.005 |
| Event Level | 1 | . |
Output 35.6.5: Iteration History Table
| EGR Iteration History | |||
|---|---|---|---|
| Iteration | Equal Opportunity | Misclassification Rate | Multi-Class Log Loss |
| 1 | 0.024185 | 0.1911 | 0.7700 |
| 2 | 0.024185 | 0.1911 | 0.7641 |
| 3 | 0.022843 | 0.1913 | 0.7673 |
| 4 | 0.021500 | 0.1914 | 0.7757 |
| 5 | 0.019571 | 0.1918 | 0.7790 |
| 6 | 0.022096 | 0.1924 | 0.7692 |
| 7 | 0.019571 | 0.1923 | 0.7820 |
| 8 | 0.017045 | 0.1919 | 0.7867 |
| 9 | 0.017045 | 0.1919 | 0.7875 |
| 10 | 0.017045 | 0.1919 | 0.7904 |
Output 35.6.6: Iteration History Graph

Note: Input data must be in a table that is accessible in your session. You can refer to this table by using a two-level name. The first level is a libref, and the second level is the table name. For more information, see the section Using SAS Viya Workbench in Chapter 2, Shared Concepts.