Sampling bias and label quality
Quick answer
Sampling bias occurs when selection systematically changes the data relative to the population the model is intended to serve. Label quality concerns how well the annotation process measures the defined target. Two reviewers may disagree because a request is ambiguous or the rubric is unclear. Agreement measures consistency, not truth. A representative sample and a reliable label policy solve different problems. Examples use local Python 3.13.5 and scikit-learn 1.8.0 where imported. All fixtures are synthetic; ByteMind library execution is unverified.
Compare collection coverage
Compare sampled request counts with a known synthetic intake population. These are coverage rates within each channel, not class probabilities.
population = {'web': 80, 'email': 20}sample = {'web': 40, 'email': 2}print({k: sample[k]/n for k,n in population.items()})Expected output:
{'web': 0.5, 'email': 0.1}Email requests are underrepresented relative to the intake mix. Collect a more representative sample or document the gap; weighting requires justified inclusion probabilities and cannot recover absent information.
Measure two-reviewer agreement
Both reviewers label the same five requests independently as billing or technical. Cohen’s unweighted kappa adjusts observed agreement for expected agreement from their separate marginal label frequencies.
from sklearn.metrics import cohen_kappa_scorea = ['billing','billing','technical','technical','billing']b = ['billing','technical','technical','technical','billing']print(sum(x == y for x,y in zip(a,b))/len(a))print(round(cohen_kappa_score(a,b), 6))Expected output:
0.80.615385Four of five agree. Expected agreement is (3/5)(2/5)+(2/5)(3/5)=0.48, so kappa=(0.8-0.48)/(1-0.48)=0.615385. This tiny sample is illustrative, not a reliable quality threshold.
Common mistakes
Convenience sampling and collecting only resolved tickets omit some cases. Define the target population, sampling frame, inclusion criteria and known omissions. Use a written rubric, independent labels and a disagreement review; retain the original labels and an adjudication record. Allow an uncertain category or abstention when justified. High agreement can coexist with shared error. Kappa can be negative and is undefined when expected agreement is one; do not turn undefined into perfect agreement. Report missing labels, sample size and class prevalence alongside agreement.
Practice and next steps
Design a rubric distinguishing payment questions from product malfunctions. Explain how to handle mixed requests without forcing an unsupported label. Calculate raw agreement on a new pair of aligned lists. Next, document collection choices in a dataset card. The separate pure-Python exercise assesses the underlying calculation, not library execution.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Sampling bias and label quality — knowledge check
Apply data collection, labeling and provenance reasoning to synthetic examples.
If 40 of 80 web and 2 of 20 email tickets are sampled, which channel has lower coverage?
Four of five aligned labels match. What is observed agreement?
What does high agreement alone establish?
If expected agreement equals one, what happens to the kappa denominator?
What should happen to original conflicting labels after adjudication?