Ethical AI · Intermediate level

Intermediate level · Module 5: Bias Mitigation Strategies · Lesson 1 of 3

Pre-processing: Fixing Data and Reweighting

Learners improve the data before training by collecting missing groups, correcting labels and reweighting under-represented groups with scikit-learn's sample_weight.

In this lesson you will

  • Apply data-level fixes before modelling
  • Reweight training examples with sample_weight

Key concepts

data collection fixeslabel correctionreweightingsample_weightCorrelationRemover

The lesson

The most effective mitigation is often better data: collecting more records from under-represented counties, fixing measurement problems and reviewing doubtful labels. These fixes take time but address causes rather than symptoms.

Reweighting gives under-represented group-and-label combinations more weight during training, so that the model pays more attention to them. Most scikit-learn estimators accept a sample_weight argument in fit(). A simple weight is the expected share of a group-label combination divided by its observed share.

Fairlearn's CorrelationRemover (in fairlearn.preprocessing) reduces the linear correlation between features and a sensitive attribute. It can reduce proxy effects, but it changes the features, so the results must be checked again.

Step by step

  1. Compute the observed count of each group-label combination in the training set.
  2. Compute weights: (group share × label share) ÷ observed combination share.
  3. Fit the baseline model again with model.fit(X_train, y_train, sample_weight=w).
  4. Recompute the MetricFrame and compare it with the baseline.

Practice activity

Apply reweighting to the project model and record the before/after accuracy and fairness metrics.

Expected result: A correct reweighting experiment with a clear before/after table.

Check your understanding

  1. What does reweighting do?

    Show answer

    It gives under-represented group-label combinations more influence during training.

  2. Why is collecting better data often the best mitigation?

    Show answer

    It addresses the cause of the bias rather than adjusting the model afterwards.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.