Complete the code to load a face recognition dataset.
from sklearn.datasets import fetch_lfw_people faces = fetch_lfw_people(min_faces_per_person=[1])
The parameter min_faces_per_person filters people with at least 70 images, ensuring enough data per person for fairness analysis.
Complete the code to split data into training and testing sets.
from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(faces.data, faces.target, test_size=[1], random_state=42)
A test size of 0.2 means 20% of data is for testing, which is common for balanced evaluation.
Fix the error in the model training code by completing the missing classifier.
from sklearn.svm import [1] model = [1](class_weight='balanced') model.fit(X_train, y_train)
LinearSVC supports class_weight='balanced' which helps fairness by adjusting for class imbalance.
Fill both blanks to compute accuracy and balanced accuracy for fairness evaluation.
from sklearn.metrics import [1], [2] acc = [1](y_test, y_pred) bal_acc = [2](y_test, y_pred)
accuracy_score measures overall correctness, while balanced_accuracy_score accounts for class imbalance, important for fairness.
Fill all three blanks to create a dictionary of fairness metrics by group.
fairness_metrics = {group: [1](y_true[group], y_pred[group]) for group in groups if len(y_true[group]) > 0}
# Use [2] to measure fairness
# Use [3] to measure overall accuracyWe compute balanced_accuracy_score per group for fairness, use f1_score as a fairness-related metric, and accuracy_score for overall accuracy.