TExcelTAD
Home › Data Science › DS Ethics & Bias

DS Ethics & Bias

Data science affects people: who gets a loan, which neighbourhoods get bus stops, which riders see a discount. Data and models can encode unfairness, invade privacy and mislead — usually not through malice, but through unexamined choices. Ethical practice means asking, at every step, who could be harmed, and how would we know?

Where bias enters

Stage Example at Riverside Bikes
Collection The satisfaction survey is only in the app, so riders without smartphones are never heard
Sampling Stations were first installed in the wealthy centre; data from outer districts is thin
Measurement "Demand" is measured as rentals — but empty stations can't record the riders who wanted a bike
Labelling Staff flag "suspicious" accounts by gut feeling, and the model learns their prejudices
Modelling A model optimised for total rides ignores districts with few riders
Deployment Bikes are rebalanced towards "high-demand" stations — making low-demand stations even emptier

The last row is a feedback loop: the model's decisions shape the next data it learns from.

A feedback loop in action

Suppose bikes are distributed in proportion to last week's rentals. A district that starts with fewer bikes records fewer rentals (because riders find empty docks), gets even fewer bikes, and so on — even though true demand is equal:

python · try it yourself
true_demand = {"Centre": 100, "Eastside": 100}     # riders who WANT a bike each day
bikes = {"Centre": 60, "Eastside": 40}              # unequal start
fleet = 100

for week in range(1, 6):
    rentals = {d: min(true_demand[d], bikes[d] * 1.5) for d in bikes}
    total = sum(rentals.values())
    bikes = {d: round(fleet * rentals[d] / total) for d in bikes}
    print(f"week {week}: rentals {rentals}  -> next week's bikes {bikes}")
week 1: rentals {'Centre': 90.0, 'Eastside': 60.0}  -> next week's bikes {'Centre': 60, 'Eastside': 40}
week 2: rentals {'Centre': 90.0, 'Eastside': 60.0}  -> next week's bikes {'Centre': 60, 'Eastside': 40}
week 3: rentals {'Centre': 90.0, 'Eastside': 60.0}  -> next week's bikes {'Centre': 60, 'Eastside': 40}
week 4: rentals {'Centre': 90.0, 'Eastside': 60.0}  -> next week's bikes {'Centre': 60, 'Eastside': 40}
week 5: rentals {'Centre': 90.0, 'Eastside': 60.0}  -> next week's bikes {'Centre': 60, 'Eastside': 40}

Demand is identical, yet Eastside never catches up: the rentals data reflects the supply the model created, not the riders' needs. Fixing it requires measuring the right thing (e.g. failed unlock attempts, app searches) — not a better algorithm.

Checking a model for unequal errors

A model can be accurate on average and still systematically wrong for one group. Always break your evaluation down by relevant groups:

python · try it yourself
import numpy as np
import pandas as pd

rng = np.random.default_rng(5)
n = 200
district = np.where(rng.random(n) < 0.8, "Centre", "Eastside")
temp = rng.uniform(5, 28, n)
# Eastside riders ride less in the cold (no sheltered docks) - but the model doesn't know
true = 40 + 3 * temp - np.where(district == "Eastside", 0.8 * (28 - temp), 0) + rng.normal(0, 6, n)
df = pd.DataFrame({"district": district, "temp_c": temp, "rides": true})

# model fitted on all stations together, without the district
slope, intercept = np.polyfit(df["temp_c"], df["rides"], 1)
df["error"] = df["rides"] - (intercept + slope * df["temp_c"])

print("overall mean abs error:", round(df["error"].abs().mean(), 1))
print(df.groupby("district")["error"].agg(["count", "mean", lambda e: e.abs().mean()])
        .rename(columns={"<lambda_0>": "mean_abs"}).round(1))
overall mean abs error: 5.5
          count  mean  mean_abs
district
Centre      161   1.4       5.1
Eastside     39  -5.8       7.2

The overall error looks fine, but the model systematically over-predicts Eastside (mean error clearly negative) because the larger Centre group dominates the fit. If Eastside's bike allocation were based on this model, it would be planned for riders who don't come — and the real cause (no sheltered docks) would stay invisible.

Privacy

Trip data is personal data. A start station, an end station and a time are often enough to identify a person — and from there their home, workplace and habits.

  • Collect only what you need (data minimisation).
  • Aggregate before sharing: counts per station per hour, not individual trips.
  • Suppress small counts: a cell with "1 trip from Mill Lane at 5 am" identifies someone.
  • Remove or coarsen identifiers (round times, drop exact coordinates).
  • Know the law that applies (e.g. GDPR in the EU).
python · try it yourself
import pandas as pd

trips = pd.DataFrame({
    "start": ["Old Bridge"] * 6 + ["Market Sq"] * 4 + ["Mill Lane"],
    "hour":  [8, 8, 8, 9, 9, 9, 8, 8, 8, 9, 5],
})
counts = trips.groupby(["start", "hour"]).size().reset_index(name="trips")
counts["trips_published"] = counts["trips"].where(counts["trips"] >= 3, other="<3")
print(counts)
        start  hour  trips trips_published
0   Market Sq     8      3               3
1   Market Sq     9      1              <3
2   Mill Lane     5      1              <3
3  Old Bridge     8      3               3
4  Old Bridge     9      3               3

Honest analysis

Ethics also covers how you treat the evidence:

  • Don't p-hack: decide the analysis before seeing results; report all the tests you ran.
  • Don't cherry-pick: show the periods, groups and charts that disagree with your story too.
  • Don't overstate: associations are not causes; one city is not every city.
  • Make it reproducible: share code and describe the data, so others can check you.

A short checklist

  1. Who is represented in the data — and who is missing?
  2. Does the target measure what we really care about?
  3. Are errors similar across groups that matter?
  4. Could the model's decisions create a feedback loop?
  5. Is personal data minimised, aggregated and protected?
  6. Would I be comfortable explaining this analysis to the people it affects?

Test yourself

Why can rentals data underestimate demand at some stations?

  1. Rentals are always exact
  2. When a station is empty, riders who wanted a bike leave no record
  3. Bikes are counted twice
  4. Weather data is missing

A model has a small overall error but systematically over-predicts one district. What should you do?

  1. Nothing; the overall error is fine
  2. Report errors by group and investigate the cause (e.g. a missing variable)
  3. Delete that district's data
  4. Increase the test set

Why suppress small counts (e.g. fewer than 3 trips) in published tables?

  1. They are usually errors
  2. They can identify individual people
  3. They make charts ugly
  4. They lower the mean