Fair AI Tools Action Set
Mitigate Demographic Parity for a Nominal Target Variable with a Nominal Sensitive Variable
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 model in order to reduce bias according to the demographic parity metric by using the data set simdata that is described in Example 15.1.
The following statements use the mitigateBias action to run the EGR algorithm in order to train a model with reduced demographic parity bias, calculated on the sensitive attribute mySensitiveVariable:
proc cas;
fairAITools.mitigateBias /
biasMetric="DEMOGRAPHICPARITY",
bound="200",
cutoff="0.33",
event="A",
learningRate="0.01",
maxIters="10",
predictedVariables={"P_nominalTargetA", "P_nominalTargetB",
"P_nominalTargetC"},
response="nominalTarget",
responseLevels={"A", "B", "C"},
seed="12345",
sensitiveVariable="mySensitiveVariable",
table="simdata",
tolerance="0.005",
trainProgram="
decisionTree.gbtreeTrain result=train_res /
table=table,
weight=weight,
target=""nominalTarget"",
inputs={
""linearPredictor"",
""absolutePredictor"",
""quadraticPredictor"",
""sinusoidPredictor""
},
nominals={""nominalTarget""},
nBins=50,
quantileBin=True,
maxLevel=5,
maxBranch=2,
leafSize=5,
missing=""USEINSEARCH"",
minUseInSearch=1,
binOrder=True,
varImp=True,
mergeBin=True,
encodeName=True,
nTree=500,
seed=12345,
ridge=1 ,
savestate={
name =""gb_astore"",
replace=True
}
;
astore.score result=score_res /
table=table,
rstore=""gb_astore"",
casout=casout,
copyVars=copyVars
;
";
run;
The table parameter names the input reference data table. The response parameter specifies the name of the target variable nominalTarget for the training model. The sensitiveVariable parameter specifies that the variable mySensitiveVariable be used as the sensitive variable in assessing bias and mitigating bias. The trainProgram parameter specifies the CASL program that contains the training and scoring code. The predictedVariables parameter specifies that the variables P_nominalTargetA, P_nominalTargetB, and P_nominalTargetC be used as the model predictions. A predicted variable is given for each level of the response variable. The responseLevels parameter specifies the levels of the target that correspond to each variable listed in the predictedVariables parameter. The order of the response levels must match the order of the predicted variables. The event parameter specifies that the level 'A' be used as the event level for the response variable. The cutoff parameter specifies the threshold of the prediction to be counted as the event. In this example, any observation whose prediction of P_nominalTargetA is greater than or equal to 0.33 is counted as an event. The biasMetric parameter specifies that the fairness measurement is demographic parity. The bound parameter specifies the value of the hyperparameter bound in the EGR algorithm. The learningRate parameter specifies the value of the learning rate in the EGR algorithm. If the tuneBound parameter is set to True, the learningRate parameter should be set to 0.01, because the bound value tuner uses the fixed learning rate of 0.01 initially. The maxIters parameter specifies the maximum number of iterations of the EGR algorithm. The seed parameter specifies the seed to use for pseudorandom number generation. The tolerance parameter specifies the threshold for constraint violations. Because constraint violations are calculated by using the difference in bias metrics between the individual sensitive attribute and the overall population, the tolerance value refers to the maximum difference in bias metrics between the individual sensitive attribute and the overall population. When the tolerance condition is satisfied, the EGR algorithm stops, and in this case, the number of iterations of the EGR algorithm might be less than the specified maxIters parameter value.
The "Mitigation Information" table that these statements produce is shown in Output 15.10.1. The table shows some key information about the model and values of the key hyperparameters that the EGR algorithm uses. The "Constraint History" table that these statements produce is shown in Output 15.10.2. The table displays the iteration history of demographic parity of each sensitive attribute, the demographic parity of the whole population, the constraint violations Gamma, the overall misclassification rate, the overall multiclass log loss, and the portion of the input data set that each sensitive attribute level occupies. In this table, "Proportion Into Event Level for Sensitive Level" refers to demographic parity for each subgroup of the variable mySensitiveVariable. From the table, you can see that without bias mitigation, the maximum demographic parity gap among those three sensitive attributes is about 37%, and after 10 iterations of the EGR algorithm it has been reduced to about 1%. Meanwhile, the overall misclassification rate increases about 2%. Compared to the previous bias mitigation examples, the drop in accuracy in this example is somewhat larger, but the behavior is expected, because having more constraints decreases the feasible solution space and the solutions are less optimal.
The "Group Metrics" table that these statements produce is shown in Output 15.10.3. The table displays the model assessment statistics and average prediction for each sensitive attribute during each iteration of the EGR algorithm.
Output 15.10.1: Mitigation Information
| Mitigation Information | ||
|---|---|---|
| Description | Character Value | Value |
| Bias Metric | DEMOGRAPHICPARITY | . |
| Sensitive Variable | mySensitiveVariable | . |
| Response | nominalTarget | . |
| Bound Value | 200 | 200 |
| Learning Rate | 0.01 | 0.01 |
| Maximum Iteration | 10 | 10 |
| Tolerance | 0.005 | 0.005 |
| Event Level | A | . |
Output 15.10.2: Constraint History
| Constraint History | ||||||||
|---|---|---|---|---|---|---|---|---|
| Iteration | mySensitiveVariable | Proportion Into Event Level for Sensitive Level | Overall Proportion Into Event Level | Gamma Max | Gamma Min | Overall Misclassification Rate | Overall Multi-Class Log Loss | Proportion |
| 1 | ComparisonGroup | 0.432167 | 0.320160 | 0.112007 | -0.112007 | 0.5009 | 0.8114 | 0.333333 |
| HighPriorGroup | 0.079271 | 0.320160 | -0.240889 | 0.240889 | 0.5009 | 0.8114 | 0.333333 | |
| IncompleteGroup | 0.449042 | 0.320160 | 0.128882 | -0.128882 | 0.5009 | 0.8114 | 0.333333 | |
| 2 | ComparisonGroup | 0.408115 | 0.284479 | 0.123635 | -0.123635 | 0.5055 | 0.8173 | 0.333333 |
| HighPriorGroup | 0.079594 | 0.284479 | -0.204885 | 0.204885 | 0.5055 | 0.8173 | 0.333333 | |
| IncompleteGroup | 0.365729 | 0.284479 | 0.081250 | -0.081250 | 0.5055 | 0.8173 | 0.333333 | |
| 3 | ComparisonGroup | 0.375281 | 0.252806 | 0.122476 | -0.122476 | 0.5026 | 0.8294 | 0.333333 |
| HighPriorGroup | 0.077990 | 0.252806 | -0.174816 | 0.174816 | 0.5026 | 0.8294 | 0.333333 | |
| IncompleteGroup | 0.305146 | 0.252806 | 0.052340 | -0.052340 | 0.5026 | 0.8294 | 0.333333 | |
| 4 | ComparisonGroup | 0.326917 | 0.221372 | 0.105545 | -0.105545 | 0.4965 | 0.8847 | 0.333333 |
| HighPriorGroup | 0.077802 | 0.221372 | -0.143569 | 0.143569 | 0.4965 | 0.8847 | 0.333333 | |
| IncompleteGroup | 0.259396 | 0.221372 | 0.038024 | -0.038024 | 0.4965 | 0.8847 | 0.333333 | |
| 5 | ComparisonGroup | 0.346375 | 0.327295 | 0.019080 | -0.019080 | 0.5491 | 1.0095 | 0.333333 |
| HighPriorGroup | 0.391344 | 0.327295 | 0.064049 | -0.064049 | 0.5491 | 1.0095 | 0.333333 | |
| IncompleteGroup | 0.244167 | 0.327295 | -0.083128 | 0.083128 | 0.5491 | 1.0095 | 0.333333 | |
| 6 | ComparisonGroup | 0.302531 | 0.264667 | 0.037865 | -0.037865 | 0.5137 | 0.9553 | 0.333333 |
| HighPriorGroup | 0.218750 | 0.264667 | -0.045917 | 0.045917 | 0.5137 | 0.9553 | 0.333333 | |
| IncompleteGroup | 0.272719 | 0.264667 | 0.008052 | -0.008052 | 0.5137 | 0.9553 | 0.333333 | |
| 7 | ComparisonGroup | 0.311365 | 0.302896 | 0.008469 | -0.008469 | 0.5326 | 0.9882 | 0.333333 |
| HighPriorGroup | 0.327521 | 0.302896 | 0.024625 | -0.024625 | 0.5326 | 0.9882 | 0.333333 | |
| IncompleteGroup | 0.269802 | 0.302896 | -0.033094 | 0.033094 | 0.5326 | 0.9882 | 0.333333 | |
| 8 | ComparisonGroup | 0.295813 | 0.279226 | 0.016587 | -0.016587 | 0.5264 | 0.9726 | 0.333333 |
| HighPriorGroup | 0.259344 | 0.279226 | -0.019882 | 0.019882 | 0.5264 | 0.9726 | 0.333333 | |
| IncompleteGroup | 0.282521 | 0.279226 | 0.003295 | -0.003295 | 0.5264 | 0.9726 | 0.333333 | |
| 9 | ComparisonGroup | 0.297063 | 0.294392 | 0.002670 | -0.002670 | 0.5299 | 0.9841 | 0.333333 |
| HighPriorGroup | 0.304000 | 0.294392 | 0.009608 | -0.009608 | 0.5299 | 0.9841 | 0.333333 | |
| IncompleteGroup | 0.282115 | 0.294392 | -0.012278 | 0.012278 | 0.5299 | 0.9841 | 0.333333 | |
| 10 | ComparisonGroup | 0.292667 | 0.286684 | 0.005983 | -0.005983 | 0.5268 | 0.9778 | 0.333333 |
| HighPriorGroup | 0.281292 | 0.286684 | -0.005392 | 0.005392 | 0.5268 | 0.9778 | 0.333333 | |
| IncompleteGroup | 0.286094 | 0.286684 | -0.000590 | 0.000590 | 0.5268 | 0.9778 | 0.333333 | |
Output 15.10.3: Group Metrics History
| Group Metrics | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Iteration | mySensitiveVariable | Number of Observations | True Positive Rate | False Positive Rate | Area Under ROC | Misclassification Rate | Multi-Class Log Loss | Best Kolmogorov-Smirnov Along ROC | Cumulative Lift | Cumulative Response | Proportion Into Event Level | Average Prediction for Event |
| 1 | ComparisonGroup | 96000 | 0.8709 | 0.2169 | 0.9149 | 0.4339 | 0.7876 | 0.6537 | 2.9300 | 29.2997 | 0.4322 | 0.3293 |
| HighPriorGroup | 96000 | 0.6092 | 0.0400 | 0.9525 | 0.6080 | 0.7881 | 0.8143 | 7.0311 | 70.3111 | 0.0793 | 0.0688 | |
| IncompleteGroup | 96000 | 0.8277 | 0.2621 | 0.8720 | 0.4607 | 0.8586 | 0.5649 | 2.7116 | 27.1163 | 0.4490 | 0.3301 | |
| 2 | ComparisonGroup | 96000 | 0.8440 | 0.1942 | 0.9137 | 0.4358 | 0.7924 | 0.6512 | 2.9290 | 29.2902 | 0.4081 | 0.3076 |
| HighPriorGroup | 96000 | 0.6125 | 0.0401 | 0.9551 | 0.6194 | 0.7895 | 0.8194 | 7.0704 | 70.7037 | 0.0796 | 0.0690 | |
| IncompleteGroup | 96000 | 0.7324 | 0.1847 | 0.8700 | 0.4613 | 0.8699 | 0.5619 | 2.7082 | 27.0816 | 0.3657 | 0.2822 | |
| 3 | ComparisonGroup | 96000 | 0.7980 | 0.1678 | 0.9102 | 0.4333 | 0.8044 | 0.6427 | 2.9262 | 29.2617 | 0.3753 | 0.2837 |
| HighPriorGroup | 96000 | 0.5977 | 0.0395 | 0.9544 | 0.6039 | 0.7918 | 0.8208 | 7.0462 | 70.4621 | 0.0780 | 0.0684 | |
| IncompleteGroup | 96000 | 0.6474 | 0.1362 | 0.8663 | 0.4705 | 0.8919 | 0.5581 | 2.7075 | 27.0753 | 0.3051 | 0.2487 | |
| 4 | ComparisonGroup | 96000 | 0.7239 | 0.1321 | 0.8936 | 0.4412 | 0.8512 | 0.6171 | 2.9252 | 29.2522 | 0.3269 | 0.2812 |
| HighPriorGroup | 96000 | 0.5510 | 0.0427 | 0.9107 | 0.5686 | 0.8748 | 0.6718 | 6.2685 | 62.6850 | 0.0778 | 0.1452 | |
| IncompleteGroup | 96000 | 0.5745 | 0.1038 | 0.8514 | 0.4798 | 0.9281 | 0.5400 | 2.7022 | 27.0217 | 0.2594 | 0.2325 | |
| 5 | ComparisonGroup | 96000 | 0.6533 | 0.1958 | 0.7959 | 0.4714 | 0.9412 | 0.4581 | 2.9050 | 29.0497 | 0.3464 | 0.3123 |
| HighPriorGroup | 96000 | 0.5593 | 0.3789 | 0.6233 | 0.6710 | 1.1075 | 0.1894 | 1.8137 | 18.1365 | 0.3913 | 0.3130 | |
| IncompleteGroup | 96000 | 0.5044 | 0.1157 | 0.7944 | 0.5050 | 0.9798 | 0.4131 | 2.6588 | 26.5884 | 0.2442 | 0.2338 | |
| 6 | ComparisonGroup | 96000 | 0.6484 | 0.1328 | 0.8339 | 0.4573 | 0.9128 | 0.5213 | 2.9195 | 29.1953 | 0.3025 | 0.2904 |
| HighPriorGroup | 96000 | 0.5125 | 0.1970 | 0.7332 | 0.6080 | 1.0168 | 0.3529 | 3.0353 | 30.3534 | 0.2188 | 0.2489 | |
| IncompleteGroup | 96000 | 0.5810 | 0.1205 | 0.8287 | 0.4757 | 0.9364 | 0.4960 | 2.7097 | 27.0974 | 0.2727 | 0.2498 | |
| 7 | ComparisonGroup | 96000 | 0.6201 | 0.1599 | 0.7965 | 0.4703 | 0.9417 | 0.4568 | 2.8996 | 28.9959 | 0.3114 | 0.2961 |
| HighPriorGroup | 96000 | 0.5181 | 0.3134 | 0.6423 | 0.6455 | 1.0737 | 0.2227 | 2.0069 | 20.0695 | 0.3275 | 0.2910 | |
| IncompleteGroup | 96000 | 0.5592 | 0.1269 | 0.8125 | 0.4819 | 0.9491 | 0.4594 | 2.6899 | 26.8988 | 0.2698 | 0.2498 | |
| 8 | ComparisonGroup | 96000 | 0.6192 | 0.1371 | 0.8115 | 0.4677 | 0.9341 | 0.4862 | 2.9069 | 29.0687 | 0.2958 | 0.2877 |
| HighPriorGroup | 96000 | 0.4974 | 0.2417 | 0.6830 | 0.6271 | 1.0428 | 0.2765 | 2.4101 | 24.1015 | 0.2593 | 0.2667 | |
| IncompleteGroup | 96000 | 0.5896 | 0.1309 | 0.8234 | 0.4843 | 0.9410 | 0.4854 | 2.6987 | 26.9871 | 0.2825 | 0.2563 | |
| 9 | ComparisonGroup | 96000 | 0.6029 | 0.1470 | 0.7931 | 0.4723 | 0.9449 | 0.4567 | 2.8980 | 28.9801 | 0.2971 | 0.2898 |
| HighPriorGroup | 96000 | 0.4938 | 0.2899 | 0.6456 | 0.6395 | 1.0652 | 0.2226 | 2.0160 | 20.1601 | 0.3040 | 0.2841 | |
| IncompleteGroup | 96000 | 0.5809 | 0.1346 | 0.8167 | 0.4780 | 0.9423 | 0.4696 | 2.6877 | 26.8768 | 0.2821 | 0.2562 | |
| 10 | ComparisonGroup | 96000 | 0.6040 | 0.1399 | 0.8003 | 0.4713 | 0.9410 | 0.4683 | 2.9088 | 29.0877 | 0.2927 | 0.2866 |
| HighPriorGroup | 96000 | 0.4926 | 0.2656 | 0.6622 | 0.6320 | 1.0525 | 0.2446 | 2.1580 | 21.5796 | 0.2813 | 0.2749 | |
| IncompleteGroup | 96000 | 0.5899 | 0.1361 | 0.8206 | 0.4772 | 0.9399 | 0.4782 | 2.6858 | 26.8579 | 0.2861 | 0.2587 | |
Mitigate Demographic Parity for a Nominal Target Variable with a Nominal Sensitive Variable
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 trains a model in order to reduce bias according to the demographic parity metric by using the data set simdata that is described in Example 15.1.
The following statements use the mitigateBias action to run the EGR algorithm in order to train a model with reduced demographic parity bias, calculated on the sensitive attribute mySensitiveVariable:
fairAITools.mitigateBias{
table='simdata',
predictedVariables={
'P_nominalTargetA',
'P_nominalTargetB',
'P_nominalTargetC'
},
response='nominalTarget',
responseLevels={'A', 'B', 'C'},
event='A',
sensitiveVariable='mySensitiveVariable',
biasMetric='DEMOGRAPHICPARITY',
learningRate=0.01,
bound=200,
tolerance=0.005,
maxIters=10,
cutoff=0.33,
seed=12345,
trainProgram= '
decisionTree.gbtreeTrain result=train_res /
table=table,
weight=weight,
target="nominalTarget",
inputs={
"linearPredictor",
"absolutePredictor",
"quadraticPredictor",
"sinusoidPredictor"
},
nominals={"nominalTarget"},
nBins=50,
quantileBin=True,
maxLevel=5,
maxBranch=2,
leafSize=5,
missing="USEINSEARCH",
minUseInSearch=1,
binOrder=True,
varImp=True,
mergeBin=True,
encodeName=True,
nTree=500,
seed=12345,
ridge=1 ,
savestate={
name ="gb_astore",
replace=True
}
;
astore.score result=score_res /
table=table,
rstore="gb_astore",
casout=casout,
copyVars=copyVars
;
'
}
The table parameter names the input reference data table. The response parameter specifies the name of the target variable nominalTarget for the training model. The sensitiveVariable parameter specifies that the variable mySensitiveVariable be used as the sensitive variable in assessing bias and mitigating bias. The trainProgram parameter specifies the CASL program that contains the training and scoring code. The predictedVariables parameter specifies that the variables P_nominalTargetA, P_nominalTargetB, and P_nominalTargetC be used as the model predictions. A predicted variable is given for each level of the response variable. The responseLevels parameter specifies the levels of the target that correspond to each variable listed in the predictedVariables parameter. The order of the response levels must match the order of the predicted variables. The event parameter specifies that the level 'A' be used as the event level for the response variable. The cutoff parameter specifies the threshold of the prediction to be counted as the event. In this example, any observation whose prediction of P_nominalTargetA is greater than or equal to 0.33 is counted as an event. The biasMetric parameter specifies that the fairness measurement is demographic parity. The bound parameter specifies the value of the hyperparameter bound in the EGR algorithm. The learningRate parameter specifies the value of the learning rate in the EGR algorithm. If the tuneBound parameter is set to True, the learningRate parameter should be set to 0.01, because the bound value tuner uses the fixed learning rate of 0.01 initially. The maxIters parameter specifies the maximum number of iterations of the EGR algorithm. The seed parameter specifies the seed to use for pseudorandom number generation. The tolerance parameter specifies the threshold for constraint violations. Because constraint violations are calculated by using the difference in bias metrics between the individual sensitive attribute and the overall population, the tolerance value refers to the maximum difference in bias metrics between the individual sensitive attribute and the overall population. When the tolerance condition is satisfied, the EGR algorithm stops, and in this case, the number of iterations of the EGR algorithm might be less than the specified maxIters parameter value.
Mitigate Demographic Parity for a Nominal Target Variable with a Nominal Sensitive Variable
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 trains a model in order to reduce bias according to the demographic parity metric by using the data set simdata that is described in Example 15.1.
The following statements use the mitigateBias action to run the EGR algorithm in order to train a model with reduced demographic parity bias, calculated on the sensitive attribute mySensitiveVariable:
s.fairaitools.mitigatebias(
biasMetric='DEMOGRAPHICPARITY',
bound='200',
cutoff='0.33',
event='A',
learningRate='0.01',
maxIters='10',
predictedVariables=['P_nominalTargetA', 'P_nominalTargetB',
'P_nominalTargetC'],
response='nominalTarget',
responseLevels=['A', 'B', 'C'],
seed='12345',
sensitiveVariable='mySensitiveVariable',
table='simdata',
tolerance='0.005',
trainProgram='''
decisionTree.gbtreeTrain result=train_res /
table=table,
weight=weight,
target="nominalTarget",
inputs={
"linearPredictor",
"absolutePredictor",
"quadraticPredictor",
"sinusoidPredictor"
},
nominals={"nominalTarget"},
nBins=50,
quantileBin=True,
maxLevel=5,
maxBranch=2,
leafSize=5,
missing="USEINSEARCH",
minUseInSearch=1,
binOrder=True,
varImp=True,
mergeBin=True,
encodeName=True,
nTree=500,
seed=12345,
ridge=1 ,
savestate={
name ="gb_astore",
replace=True
}
;
astore.score result=score_res /
table=table,
rstore="gb_astore",
casout=casout,
copyVars=copyVars
;
''')
The table parameter names the input reference data table. The response parameter specifies the name of the target variable nominalTarget for the training model. The sensitiveVariable parameter specifies that the variable mySensitiveVariable be used as the sensitive variable in assessing bias and mitigating bias. The trainProgram parameter specifies the CASL program that contains the training and scoring code. The predictedVariables parameter specifies that the variables P_nominalTargetA, P_nominalTargetB, and P_nominalTargetC be used as the model predictions. A predicted variable is given for each level of the response variable. The responseLevels parameter specifies the levels of the target that correspond to each variable listed in the predictedVariables parameter. The order of the response levels must match the order of the predicted variables. The event parameter specifies that the level 'A' be used as the event level for the response variable. The cutoff parameter specifies the threshold of the prediction to be counted as the event. In this example, any observation whose prediction of P_nominalTargetA is greater than or equal to 0.33 is counted as an event. The biasMetric parameter specifies that the fairness measurement is demographic parity. The bound parameter specifies the value of the hyperparameter bound in the EGR algorithm. The learningRate parameter specifies the value of the learning rate in the EGR algorithm. If the tuneBound parameter is set to True, the learningRate parameter should be set to 0.01, because the bound value tuner uses the fixed learning rate of 0.01 initially. The maxIters parameter specifies the maximum number of iterations of the EGR algorithm. The seed parameter specifies the seed to use for pseudorandom number generation. The tolerance parameter specifies the threshold for constraint violations. Because constraint violations are calculated by using the difference in bias metrics between the individual sensitive attribute and the overall population, the tolerance value refers to the maximum difference in bias metrics between the individual sensitive attribute and the overall population. When the tolerance condition is satisfied, the EGR algorithm stops, and in this case, the number of iterations of the EGR algorithm might be less than the specified maxIters parameter value.
Mitigate Demographic Parity for a Nominal Target Variable with a Nominal Sensitive Variable
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 trains a model in order to reduce bias according to the demographic parity metric by using the data set simdata that is described in Example 15.1.
The following statements use the mitigateBias action to run the EGR algorithm in order to train a model with reduced demographic parity bias, calculated on the sensitive attribute mySensitiveVariable:
cas.fairAITools.mitigateBias(s,
biasMetric='DEMOGRAPHICPARITY',
bound='200',
cutoff='0.33',
event='A',
learningRate='0.01',
maxIters='10',
predictedVariables=c('P_nominalTargetA', 'P_nominalTargetB',
'P_nominalTargetC'),
response='nominalTarget',
responseLevels=c('A', 'B', 'C'),
seed='12345',
sensitiveVariable='mySensitiveVariable',
table='simdata',
tolerance='0.005',
trainProgram='
decisionTree.gbtreeTrain result=train_res /
table=table,
weight=weight,
target="nominalTarget",
inputs={
"linearPredictor",
"absolutePredictor",
"quadraticPredictor",
"sinusoidPredictor"
},
nominals={"nominalTarget"},
nBins=50,
quantileBin=True,
maxLevel=5,
maxBranch=2,
leafSize=5,
missing="USEINSEARCH",
minUseInSearch=1,
binOrder=True,
varImp=True,
mergeBin=True,
encodeName=True,
nTree=500,
seed=12345,
ridge=1 ,
savestate={
name ="gb_astore",
replace=True
}
;
astore.score result=score_res /
table=table,
rstore="gb_astore",
casout=casout,
copyVars=copyVars
;
')
The table parameter names the input reference data table. The response parameter specifies the name of the target variable nominalTarget for the training model. The sensitiveVariable parameter specifies that the variable mySensitiveVariable be used as the sensitive variable in assessing bias and mitigating bias. The trainProgram parameter specifies the CASL program that contains the training and scoring code. The predictedVariables parameter specifies that the variables P_nominalTargetA, P_nominalTargetB, and P_nominalTargetC be used as the model predictions. A predicted variable is given for each level of the response variable. The responseLevels parameter specifies the levels of the target that correspond to each variable listed in the predictedVariables parameter. The order of the response levels must match the order of the predicted variables. The event parameter specifies that the level 'A' be used as the event level for the response variable. The cutoff parameter specifies the threshold of the prediction to be counted as the event. In this example, any observation whose prediction of P_nominalTargetA is greater than or equal to 0.33 is counted as an event. The biasMetric parameter specifies that the fairness measurement is demographic parity. The bound parameter specifies the value of the hyperparameter bound in the EGR algorithm. The learningRate parameter specifies the value of the learning rate in the EGR algorithm. If the tuneBound parameter is set to True, the learningRate parameter should be set to 0.01, because the bound value tuner uses the fixed learning rate of 0.01 initially. The maxIters parameter specifies the maximum number of iterations of the EGR algorithm. The seed parameter specifies the seed to use for pseudorandom number generation. The tolerance parameter specifies the threshold for constraint violations. Because constraint violations are calculated by using the difference in bias metrics between the individual sensitive attribute and the overall population, the tolerance value refers to the maximum difference in bias metrics between the individual sensitive attribute and the overall population. When the tolerance condition is satisfied, the EGR algorithm stops, and in this case, the number of iterations of the EGR algorithm might be less than the specified maxIters parameter value.