Data Science for Testers: Testing a System That Is Allowed to Be Wrong
A model does not pass or fail a test case. It has an accuracy, and your job is to decide whether that number is honest and whether it holds for the people it affects.
In this article
- The vocabulary you need, and nothing more
- Why accuracy alone is a bad metric
- What a tester actually checks
- A test you can actually write
- Monitoring after release
The vocabulary you need, and nothing more
- Features – the inputs. Training data – the examples it learned from. Labels – the right answers it was shown.
- Training, validation and test sets – three separate slices. The test set must never have been seen during training.
- Overfitting – it memorised the training data and fails on anything new. The sign is excellent training accuracy and poor test accuracy.
- Drift – the world changed after training, so yesterday's model is wrong about today.
Why accuracy alone is a bad metric
A fraud model on data where 1 transaction in 1,000 is fraudulent can predict 'not fraud' every time and be 99.9% accurate. It is also useless.
| Metric | The question it answers |
|---|---|
| Precision | Of the ones it flagged, how many really were? |
| Recall | Of the ones that really were, how many did it catch? |
| F1 | One number balancing the two, when you need a single figure |
| Confusion matrix | The four counts the others are derived from – always ask to see it |
Precision and recall trade against each other. Which one matters is a business decision, not a technical one – ask who pays for a false positive and who pays for a false negative.
What a tester actually checks
- Data leakage – does any feature contain information that would not exist at prediction time? This is the defect that produces a brilliant model and a disaster in production.
- Train/test contamination – were the same rows in both sets? Check for duplicates.
- Class balance – what does the split look like, and does the metric suit it?
- Slice performance – accuracy per segment, not only overall. A model can be 94% accurate overall and 61% for one group.
- Boundary behaviour – what does it do with a missing field, an extreme value, a format it has never seen?
- Reproducibility – same data, same seed, same result? If not, nothing downstream is testable.
A test you can actually write
import pandas as pd
def test_no_train_test_overlap(train, test, key='customer_id'):
overlap = set(train[key]) & set(test[key])
assert not overlap, f'{len(overlap)} ids are in both sets - the score is inflated'
def test_slice_performance(model, data, group='age_band', floor=0.80):
weak = {}
for name, slice_ in data.groupby(group):
score = model.score(slice_.drop(columns=['label']), slice_['label'])
if score < floor:
weak[name] = round(score, 3)
assert not weak, f'below {floor} for: {weak}'
Neither of those needs you to understand the algorithm. They need you to understand what would make the number a lie – which is exactly a tester's skill.
Monitoring after release
A model is the one component that degrades while nothing changes. Put three things in place before it ships: a record of input distributions so you can see drift, accuracy tracked against whatever ground truth arrives later, and an alert when either moves. Without them nobody finds out until a customer does.
Key points
- Accuracy on an imbalanced dataset means nothing – ask for the confusion matrix.
- Data leakage is the defect that looks like success. Hunt it first.
- Test per slice, not only overall.
- If a run is not reproducible, nothing you test downstream is either.
Practise this on the free applications at jstestingacademy.co.in/qa-apps – no account needed.

