Fair AI Tools Action Set

Mitigating Bias of a Support Vector Machine

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 trains a support vector machine in order to reduce bias according to the equal opportunity metric by using the home equity data, which are available in the sampsio.hmeq data set. The data set has a binary target named BAD, and the example uses the variable REASON as the sensitive attribute.

You can load the sampsio.hmeq data set into your CAS session by specifying your CAS engine libref in the SET statement in the following DATA step:

data mycas.hmeq;
    set sampsio.hmeq;
    where reason ne '';
run;

These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.

The following statements use the mitigateBiasSVM action to run the exponentiated gradient reduction (EGR) algorithm in order to train a model that has reduced equal opportunity bias, which is calculated on the sensitive attribute REASON. Note that the syntax of the trainOptions parameter here is the same as the syntax of the svm.svmTrain action.

proc cas;
fairAITools.mitigateBiasSVM /
    mitigateOptions={biasMetric="EQUALOPPORTUNITY",
                     bound="75",
                     event="1",
                     predictedVariables={"P_BAD1", "P_BAD0"},
                     responseLevels={"1", "0"},
                     seed="12345",
                     sensitiveVariable="REASON"},
    trainOptions={c="0.1",
                  inputs={"CLAGE",
                                   "CLNO",
                                   "DEBTINC",
                                   "LOAN",
                                   "MORTDUE",
                                   "VALUE",
                                   "YOJ",
                                   "DELINQ",
                                   "DEROG",
                                   "JOB",
                                   "NINQ"},
                  nominals={"DELINQ",
                                   "DEROG",
                                   "JOB",
                                   "NINQ",
                                   "BAD"},
                  saveState={name="hmeq_svm_astore",
                                   replace="True"},
                  seed="12345",
                  table="hmeq",
                  target="BAD"};
run;

The mitigateOptions parameter includes the following subparameters:

  • The biasMetric subparameter specifies that equal opportunity be used as the bias measurement.

  • The bound subparameter specifies 75 as the bound value for the EGR algorithm.

  • The event subparameter specifies the formatted value of the response variable that represents the event of interest.

  • The predictedVariables subparameter specifies that the variables P_BAD0 and P_BAD1 be used as the model predictions. A predicted variable is given for each level of the target variable.

  • The responseLevels subparameter specifies the levels of the target that correspond to each variable that is listed in the predictedVariables subparameter. The order of the response levels must match the order of the predicted variables.

  • The seed subparameter specifies the seed to use for pseudorandom number generation in the EGR algorithm.

  • The sensitiveVariable subparameter specifies that the variable REASON be used as the sensitive variable in assessing and mitigating bias.

The trainOptions parameter includes the following subparameters that are passed to the svm.svmTrain action call:

  • The c subparameter specifies 0.1 as the penalty for training.

  • The inputs subparameter specifies that the variables CLAGE, CLNO, DEBTINC, LOAN, MORTDUE, VALUE, YOJ, DELINQ, DEROG, JOB, and NINQ be used as inputs.

  • The nominals subparameter specifies that the variables DELINQ, DEROG, JOB, NINQ, and BAD be used as nominal variables.

  • The saveState subparameter specifies the table to store the generated analytic store model.

  • The seed subparameter specifies the seed to use for pseudorandom number generation in the training process.

  • The table subparameter names the input data table for training.

  • The target subparameter specifies that the variable BAD be used as the target variable.

The "Mitigation Information" table that these statements produce is shown in Output 15.16.1. The table shows some key information about the model and values of the key hyperparameters that the EGR algorithm uses.

The "Iteration History" table that these statements produce is shown in Output 15.16.2. The table displays the iteration history of the overall equal opportunity metric, the overall misclassification rate, and the overall multiclass log loss. From the table, you can see that without bias mitigation, the equal opportunity gap between those two sensitive attributes is about 2.4%, and after eight iterations of the EGR algorithm it has been reduced to about 0.5%. Meanwhile, the overall accuracy of the model does not change significantly.

The "Group Metrics" table that these statements produce is shown in Output 15.16.3. The table displays the model assessment statistics and average prediction for each sensitive attribute during each iteration of the EGR algorithm.

Output 15.16.1: Mitigation Information

Results from fairAITools.mitigateBiasSVM

Mitigation Information
DescriptionCharacter ValueValue
Bias MetricEQUALOPPORTUNITY.
Sensitive VariableREASON.
ResponseBAD.
Bound Value7575
Learning Rate0.010.01
Maximum Iteration1010
Tolerance0.0050.005
Event Level1.


Output 15.16.2: Iteration History

EGR Iteration History
IterationEqual OpportunityMisclassification
Rate
Multi-Class
Log Loss
10.0243440.19040.9197
20.0243440.19040.9136
30.0243440.19040.9457
40.0243440.19040.9358
50.0216600.19080.9292
60.0176330.19130.9279
70.0077590.19410.9363
80.0050740.19450.9101


Output 15.16.3: Group Metrics History

Group Metrics
IterationREASONNumber of ObservationsTrue Positive
Rate
False Positive
Rate
Area Under ROCMisclassification
Rate
Multi-Class
Log Loss
Best Kolmogorov-Smirnov
Along ROC
Cumulative LiftCumulative ResponseProportion Into
Event Level
Average Prediction
for Event
1DebtCon39280.06980.00410.54390.17970.87890.08541.436214.36240.01650.0665
 HomeImp17800.04550.00220.55140.21401.00960.11461.792917.92930.01180.0603
2DebtCon39280.06980.00410.54390.17970.87320.08541.436214.36240.01650.0666
 HomeImp17800.04550.00220.55140.21401.00280.11461.792917.92930.01180.0604
3DebtCon39280.06980.00410.54400.17970.90350.08411.436214.36240.01650.0657
 HomeImp17800.04550.00220.55140.21401.03880.11211.792917.92930.01180.0595
4DebtCon39280.06980.00410.54410.17970.89410.08411.436214.36240.01650.0659
 HomeImp17800.04550.00220.55140.21401.02760.11461.792917.92930.01180.0597
5DebtCon39280.06710.00410.54400.18020.88790.08411.436214.36240.01600.0660
 HomeImp17800.04550.00220.55140.21401.02020.11461.792917.92930.01180.0598
6DebtCon39280.06310.00410.54380.18100.88670.08411.436214.36240.01530.0660
 HomeImp17800.04550.00220.55140.21401.01870.11461.792917.92930.01180.0598
7DebtCon39280.04560.00410.54310.18430.89470.08491.436214.36240.01200.0657
 HomeImp17800.03790.00220.55120.21571.02820.11891.792917.92930.01010.0595
8DebtCon39280.04300.00410.54290.18480.87000.08411.436214.36240.01150.0664
 HomeImp17800.03790.00220.55120.21570.99880.11461.792917.92930.01010.0602


Mitigating Bias of a Support Vector Machine

This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.

For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.

This example illustrates the mitigateBiasSVM action by using the home equity data that are described in the CASL version of this example.

The following statements use the mitigateBiasSVM action to run the exponentiated gradient reduction (EGR) algorithm in order to train a model that has reduced equal opportunity bias, which is calculated on the sensitive attribute REASON. Note that the syntax of the trainOptions parameter here is the same as the syntax of the svm.svmTrain action.

mitigateOptions={biasMetric="EQUALOPPORTUNITY",
                 bound="75",
                 event="1",
                 predictedVariables={"P_BAD1", "P_BAD0"},
                 responseLevels={"1", "0"},
                 seed=12345,
                 sensitiveVariable="REASON"},
trainOptions={inputs={"CLAGE",
                 "CLNO",
                 "DEBTINC",
                 "LOAN",
                 "MORTDUE",
                 "VALUE",
                 "YOJ",
                 "DELINQ",
                 "DEROG",
                 "JOB",
                 "NINQ"},
             nominals={"DELINQ",
                   "DEROG",
                   "JOB",
                   "NINQ",
                   "BAD"},
             saveState={
                 name="hmeq_svm_astore",
                 replace=True},
             seed=12345,
            table="hmeq",
            target="BAD",
            c=0.1
 }

The mitigateOptions parameter includes the following subparameters:

  • The biasMetric subparameter specifies that equal opportunity be used as the bias measurement.

  • The bound subparameter specifies 75 as the bound value for the EGR algorithm.

  • The event subparameter specifies the formatted value of the response variable that represents the event of interest.

  • The predictedVariables subparameter specifies that the variables P_BAD0 and P_BAD1 be used as the model predictions. A predicted variable is given for each level of the target variable.

  • The responseLevels subparameter specifies the levels of the target that correspond to each variable that is listed in the predictedVariables subparameter. The order of the response levels must match the order of the predicted variables.

  • The seed subparameter specifies the seed to use for pseudorandom number generation in the EGR algorithm.

  • The sensitiveVariable subparameter specifies that the variable REASON be used as the sensitive variable in assessing and mitigating bias.

The trainOptions parameter includes the following subparameters that are passed to the svm.svmTrain action call:

  • The c subparameter specifies 0.1 as the penalty for training.

  • The inputs subparameter specifies that the variables CLAGE, CLNO, DEBTINC, LOAN, MORTDUE, VALUE, YOJ, DELINQ, DEROG, JOB, and NINQ be used as inputs.

  • The nominals subparameter specifies that the variables DELINQ, DEROG, JOB, NINQ, and BAD be used as nominal variables.

  • The saveState subparameter specifies the table to store the generated analytic store model.

  • The seed subparameter specifies the seed to use for pseudorandom number generation in the training process.

  • The table subparameter names the input data table for training.

  • The target subparameter specifies that the variable BAD be used as the target variable.

Mitigating Bias of a Support Vector Machine

This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.

For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.

This example illustrates the mitigateBiasSVM action by using the home equity data that are described in the CASL version of this example.

The following statements use the mitigateBiasSVM action to run the exponentiated gradient reduction (EGR) algorithm in order to train a model that has reduced equal opportunity bias, which is calculated on the sensitive attribute REASON. Note that the syntax of the trainOptions parameter here is the same as the syntax of the svm.svmTrain action.

s.fairaitools.mitigatebiassvm(
    mitigateOptions=dict(biasMetric='EQUALOPPORTUNITY',
                         bound='75',
                         event='1',
                         predictedVariables=['P_BAD1', 'P_BAD0'],
                         responseLevels=['1', '0'],
                         seed='12345',
                         sensitiveVariable='REASON'),
    trainOptions=dict(c='0.1',
                      inputs=['CLAGE',
                                       'CLNO',
                                       'DEBTINC',
                                       'LOAN',
                                       'MORTDUE',
                                       'VALUE',
                                       'YOJ',
                                       'DELINQ',
                                       'DEROG',
                                       'JOB',
                                       'NINQ'],
                      nominals=['DELINQ',
                                       'DEROG',
                                       'JOB',
                                       'NINQ',
                                       'BAD'],
                      saveState=dict(name='hmeq_svm_astore',
                                       replace='True'),
                      seed='12345',
                      table='hmeq',
                      target='BAD'))

The mitigateOptions parameter includes the following subparameters:

  • The biasMetric subparameter specifies that equal opportunity be used as the bias measurement.

  • The bound subparameter specifies 75 as the bound value for the EGR algorithm.

  • The event subparameter specifies the formatted value of the response variable that represents the event of interest.

  • The predictedVariables subparameter specifies that the variables P_BAD0 and P_BAD1 be used as the model predictions. A predicted variable is given for each level of the target variable.

  • The responseLevels subparameter specifies the levels of the target that correspond to each variable that is listed in the predictedVariables subparameter. The order of the response levels must match the order of the predicted variables.

  • The seed subparameter specifies the seed to use for pseudorandom number generation in the EGR algorithm.

  • The sensitiveVariable subparameter specifies that the variable REASON be used as the sensitive variable in assessing and mitigating bias.

The trainOptions parameter includes the following subparameters that are passed to the svm.svmTrain action call:

  • The c subparameter specifies 0.1 as the penalty for training.

  • The inputs subparameter specifies that the variables CLAGE, CLNO, DEBTINC, LOAN, MORTDUE, VALUE, YOJ, DELINQ, DEROG, JOB, and NINQ be used as inputs.

  • The nominals subparameter specifies that the variables DELINQ, DEROG, JOB, NINQ, and BAD be used as nominal variables.

  • The saveState subparameter specifies the table to store the generated analytic store model.

  • The seed subparameter specifies the seed to use for pseudorandom number generation in the training process.

  • The table subparameter names the input data table for training.

  • The target subparameter specifies that the variable BAD be used as the target variable.

Mitigating Bias of a Support Vector Machine

This section contains R code for the analysis in the CASL version of this example, which contains details about the results.

For more information about coding in R, see Getting Started with SAS Viya for R and SAS Viya: System Programming Guide.

This example illustrates the mitigateBiasSVM action by using the home equity data that are described in the CASL version of this example.

The following statements use the mitigateBiasSVM action to run the exponentiated gradient reduction (EGR) algorithm in order to train a model that has reduced equal opportunity bias, which is calculated on the sensitive attribute REASON. Note that the syntax of the trainOptions parameter here is the same as the syntax of the svm.svmTrain action.

cas.fairAITools.mitigateBiasSVM(s,
    mitigateOptions=list(biasMetric='EQUALOPPORTUNITY',
                         bound='75',
                         event='1',
                         predictedVariables=c('P_BAD1', 'P_BAD0'),
                         responseLevels=c('1', '0'),
                         seed='12345',
                         sensitiveVariable='REASON'),
    trainOptions=list(c='0.1',
                      inputs=c('CLAGE',
                                        'CLNO',
                                        'DEBTINC',
                                        'LOAN',
                                        'MORTDUE',
                                        'VALUE',
                                        'YOJ',
                                        'DELINQ',
                                        'DEROG',
                                        'JOB',
                                        'NINQ'),
                      nominals=c('DELINQ',
                                        'DEROG',
                                        'JOB',
                                        'NINQ',
                                        'BAD'),
                      saveState=list(name='hmeq_svm_astore',
                                        replace='True'),
                      seed='12345',
                      table='hmeq',
                      target='BAD'))

The mitigateOptions parameter includes the following subparameters:

  • The biasMetric subparameter specifies that equal opportunity be used as the bias measurement.

  • The bound subparameter specifies 75 as the bound value for the EGR algorithm.

  • The event subparameter specifies the formatted value of the response variable that represents the event of interest.

  • The predictedVariables subparameter specifies that the variables P_BAD0 and P_BAD1 be used as the model predictions. A predicted variable is given for each level of the target variable.

  • The responseLevels subparameter specifies the levels of the target that correspond to each variable that is listed in the predictedVariables subparameter. The order of the response levels must match the order of the predicted variables.

  • The seed subparameter specifies the seed to use for pseudorandom number generation in the EGR algorithm.

  • The sensitiveVariable subparameter specifies that the variable REASON be used as the sensitive variable in assessing and mitigating bias.

The trainOptions parameter includes the following subparameters that are passed to the svm.svmTrain action call:

  • The c subparameter specifies 0.1 as the penalty for training.

  • The inputs subparameter specifies that the variables CLAGE, CLNO, DEBTINC, LOAN, MORTDUE, VALUE, YOJ, DELINQ, DEROG, JOB, and NINQ be used as inputs.

  • The nominals subparameter specifies that the variables DELINQ, DEROG, JOB, NINQ, and BAD be used as nominal variables.

  • The saveState subparameter specifies the table to store the generated analytic store model.

  • The seed subparameter specifies the seed to use for pseudorandom number generation in the training process.

  • The table subparameter names the input data table for training.

  • The target subparameter specifies that the variable BAD be used as the target variable.

Last updated: August 04, 2026