Bird
Raised Fist0

Responsible AI - Fairness, Bias Detection, Mitigation Strategies

THEORYadvancedInterview freq: high
Choose your preparation mode6 modes available
⚖️
Bias Detection vs Bias Mitigation

In a machine learning model for loan approval, would you prioritize bias detection or bias mitigation? Justify your choice.

📊
Comparison
DimensionBias DetectionBias Mitigation
Effectiveness in identifying biasHighModerate
Impact on model accuracyNeutralVariable
Ease of integrationModerateComplex
Computational costHighModerate
Regulatory compliance supportHighModerate
✅
Verdict
Default to bias detection when auditing model fairness before deployment or when regulatory compliance is a concern. Switch to bias mitigation when deploying models with identified bias issues and fairness is prioritized over slight accuracy improvements.
💡
Key Insight
Understanding bias sources through detection is crucial before applying mitigation strategies to ensure fair outcomes.
⚠️
Interview Trap
❌ Wrong: Always prioritize bias mitigation because it directly improves fairness.
This ignores the importance of understanding bias sources before attempting to mitigate them.
✅ Explain the importance of detecting bias to understand its sources and then apply targeted mitigation strategies.
Bias Detection
"Identifies potential sources of bias in data and models, allowing for informed decision-making."
  • Does not directly improve model fairness; only identifies issues.
  • Can be computationally expensive with large datasets.
  • May produce false positives, leading to unnecessary concern.
  • Requires domain expertise to interpret results effectively.
Ideal When
  • When n > 100K and you need to audit model fairness before deployment.
  • When regulatory compliance requires transparency in model decisions.
  • When the model is in the early stages of development and you need to understand bias sources.
  • When you have access to diverse demographic data for analysis.
Google uses bias detection tools to audit their AI systems for fairness before deployment.
Bias Mitigation
"Actively reduces bias in models, leading to fairer outcomes."
  • May reduce model accuracy if not carefully implemented.
  • Can be complex to integrate into existing pipelines.
  • Requires continuous monitoring to ensure effectiveness.
  • Potentially introduces new biases if not properly balanced.
Ideal When
  • When n < 50K and you need to deploy a model with fairness constraints.
  • When the model is in production and bias has been identified as a critical issue.
  • When you have a clear understanding of the bias sources and can apply targeted mitigation.
  • When fairness is a higher priority than slight accuracy improvements.
IBM uses bias mitigation strategies in their AI systems to ensure fair treatment across different demographic groups.
🐍
Bias Detection - Example
▼ Show
Python
import numpy as np
from sklearn.metrics import confusion_matrix

def bias_detection(y_true, y_pred, sensitive_attr):
    cm = confusion_matrix(y_true, y_pred)
    bias_metric = cm[0, 1] / (cm[0, 1] + cm[1, 0])
    print(f'Bias metric for {sensitive_attr}: {bias_metric}')

# Example usage
bias_detection(np.array([1, 0, 1]), np.array([1, 1, 0]), 'gender')
🐍
Bias Mitigation - Example
▼ Show
Python
import numpy as np
from sklearn.preprocessing import StandardScaler

def bias_mitigation(X, y):
    scaler = StandardScaler()
    X_scaled = scaler.fit_transform(X)
    # Apply a simple bias mitigation strategy
    X_scaled[y == 1] *= 0.9
    return X_scaled

# Example usage
X = np.array([[1, 2], [3, 4], [5, 6]])
y = np.array([0, 1, 0])
X_mitigated = bias_mitigation(X, y)
✅
Use Bias Detection When
  • •When n > 100K and you need to audit model fairness before deployment.
  • •When regulatory compliance requires transparency in model decisions.
  • •When the model is in the early stages of development and you need to understand bias sources.
✅
Use Bias Mitigation When
  • •When n < 50K and you need to deploy a model with fairness constraints.
  • •When the model is in production and bias has been identified as a critical issue.
  • •When fairness is a higher priority than slight accuracy improvements.
↳
Nuances
  • Bias detection is crucial in the early stages of model development to understand potential issues.
  • Bias mitigation can sometimes introduce new biases if not carefully balanced.
  • In highly regulated industries, bias detection is often prioritized to ensure compliance.
  • Bias mitigation strategies may reduce model accuracy, which is a trade-off that needs careful consideration.

Practice

(1/5)
1. In the context of model calibration, which metric is most appropriate to evaluate the probability outputs of a classifier?
easy
A. Accuracy
B. Precision
C. Log Loss
D. F1 Score

Solution

  1. Step 1: Identify the purpose of calibration.

    Calibration aims to ensure that predicted probabilities reflect true likelihoods.
  2. Step 2: Evaluate each metric.

    Accuracy, precision, and F1 score do not consider probability estimates, only classification decisions. Log Loss penalizes incorrect probability estimates, making it suitable for calibration.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Log Loss evaluates probability accuracy. [OK]
Hint: Log Loss evaluates probability accuracy. [OK]
Common Mistakes:
2. Given the following Python code snippet using a pre-trained YOLO model, what will be the output shape of the detection results?
import torch
from torchvision.models.detection import yolo_v3

model = yolo_v3(pretrained=True)
model.eval()

input_tensor = torch.rand(1, 3, 416, 416)
output = model(input_tensor)
print(output[0]['boxes'].shape)
easy
A. (1, 4)
B. (N, 4)
C. (N, 5)
D. (1, 5)

Solution

  1. Step 1: Understand YOLO output

    YOLO outputs a list of detections, each with a bounding box of 4 coordinates.
  2. Step 2: Determine output shape

    The shape is (N, 4) where N is the number of detected objects.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    YOLO boxes = (N, 4) [OK]
Hint: YOLO boxes = (N, 4) [OK]
Common Mistakes:
3.
import shap
import xgboost

# Load data
X, y = shap.datasets.boston()

# Train model
model = xgboost.XGBRegressor().fit(X, y)

# Explain the model's predictions using SHAP
explainer = shap.Explainer(model, X)
shap_values = explainer(X)

# What is the shape of shap_values?
easy
A. (13, 506)
B. (506,)
C. (506, 13)
D. (13,)

Solution

  1. Step 1: Understand SHAP output.

    SHAP values are calculated for each feature of each instance.
  2. Step 2: Determine the shape based on input data.

    The dataset has 506 instances and 13 features, so SHAP values will have the shape (506, 13).
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    SHAP values match data shape: (instances, features). [OK]
Hint: SHAP values match data shape: (instances, features). [OK]
Common Mistakes:
4.
from sklearn.ensemble import RandomForestClassifier
import numpy as np

X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
y = np.array([0, 1, 0, 1])

model = RandomForestClassifier(n_estimators=1, max_features=1, bootstrap=False)
model.fit(X, y)

print(model.estimators_[0].tree_.feature)
What does this code output?
easy
A. [0, 1]
B. [1, 0]
C. [0]
D. [1]

Solution

  1. Step 1: Analyze the code

    The RandomForestClassifier is set with max_features=1, meaning each tree considers only one feature for splitting.
  2. Step 2: Determine the output

    Since bootstrap=False, the entire dataset is used, and the tree will choose one feature. The output shows the feature index used for splitting.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    max_features=1 limits to one feature. [OK]
Hint: max_features=1 limits to one feature. [OK]
Common Mistakes:
5. A model trained on a dataset is performing exceptionally well on the test set but poorly on new unseen data. What is the most likely cause?
medium
A. The model is overfitting due to too many parameters.
B. The test set contains data leakage from the training set.
C. The model has not been trained for enough epochs.
D. The feature scaling was not applied correctly.

Solution

  1. Step 1: Analyze the symptoms

    High test performance but poor real-world performance suggests leakage.
  2. Step 2: Eliminate other causes

    The model is overfitting due to too many parameters. would affect both test and real-world data, The model has not been trained for enough epochs. would not cause high test performance, The feature scaling was not applied correctly. would affect all data equally.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    High test, low real-world = leakage [OK]
Hint: High test, low real-world = leakage [OK]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard