0
0
ML Pythonml~10 mins

Fairness metrics in ML Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the accuracy of a model.

ML Python
accuracy = correct_predictions / [1]
Drag options to blanks, or click blank then click option'
Apredictions
Bcorrect_predictions
Ctotal_predictions
Dtotal_labels
Attempts:
3 left
💡 Hint
Common Mistakes
Dividing by correct_predictions instead of total_predictions.
Using predictions instead of total count.
2fill in blank
medium

Complete the code to calculate demographic parity difference between two groups.

ML Python
dp_difference = abs(rate_group1 - [1])
Drag options to blanks, or click blank then click option'
Arate_group1
Brate_group2
Ctotal_group2
Dtotal_group1
Attempts:
3 left
💡 Hint
Common Mistakes
Subtracting the same group's rate.
Using total counts instead of rates.
3fill in blank
hard

Fix the error in the code to compute equal opportunity difference.

ML Python
equal_opportunity_diff = tpr_group1 - [1]
Drag options to blanks, or click blank then click option'
Atpr_group2
Btpr_group1
Cfpr_group2
Dfpr_group1
Attempts:
3 left
💡 Hint
Common Mistakes
Using false positive rates instead of true positive rates.
Subtracting the same group's TPR.
4fill in blank
hard

Fill both blanks to calculate disparate impact ratio.

ML Python
disparate_impact = [1] / [2]
Drag options to blanks, or click blank then click option'
Apositive_rate_minority
Bpositive_rate_majority
Ctotal_minority
Dtotal_majority
Attempts:
3 left
💡 Hint
Common Mistakes
Using total counts instead of positive rates.
Reversing numerator and denominator.
5fill in blank
hard

Fill all three blanks to create a fairness report dictionary.

ML Python
fairness_report = {
    'demographic_parity_diff': [1],
    'equal_opportunity_diff': [2],
    'disparate_impact': [3]
}
Drag options to blanks, or click blank then click option'
Adp_difference
Bequal_opportunity_diff
Cdisparate_impact
Daccuracy
Attempts:
3 left
💡 Hint
Common Mistakes
Including accuracy instead of fairness metrics.
Mixing up metric variable names.