CASE STUDY 03 · RESPONSIBLE CLASSIFICATION

Advanced Sensitivity + Threshold Audit

Responsible Medical Classification Audit

Evaluate a teaching model with the malignant class defined as positive, stratified validation, threshold trade-offs, false-negative review and explicit clinical boundaries.

01 · SAFETY & INTENDED USE

This is an evaluation lesson—not a diagnostic system

Educational use only: The program must not be used for diagnosis, screening, treatment, triage or patient-specific advice. It is not clinically validated, not a medical device and not a substitute for qualified healthcare professionals.

The objective is to teach how classification errors change meaning in a high-stakes context. The example uses measurements from a historical teaching dataset and demonstrates a statistical workflow. Strong numbers on one dataset do not establish safety, effectiveness or generalization to another hospital, population, device or time period.

Human role

Qualified clinicians retain responsibility for medical decisions.

Model role

Demonstrate evaluation concepts under controlled conditions.

Required evidence

External and prospective validation before clinical study.

02 · DATASET & PROVENANCE

Know where the numbers came from

The program loads the Wisconsin Diagnostic Breast Cancer teaching dataset bundled with scikit-learn. It contains numeric features computed from digitized images of fine-needle aspirates. The case uses the packaged data directly and does not download patient records.

Review the official scikit-learn dataset documentation and the UCI dataset record for provenance and dataset details. The dataset is attributed transparently; it is not original CodeBhavya data.

Data questions before modeling

  • How were samples selected and are repeated measurements linked to the same patient?
  • Which instruments and feature-extraction process produced the variables?
  • Does the development population represent the intended deployment population?
  • Were labels established consistently and independently of model features?
  • Which missing, exclusion or preprocessing decisions could introduce bias?
03 · POSITIVE-CLASS DEFINITION

Metric meaning depends on label orientation

The original scikit-learn target encodes malignant as 0 and benign as 1. The program deliberately inverts it so malignant becomes positive class 1. This makes recall mean the proportion of malignant cases identified by the model.

OutcomeMeaningReview concern
True positiveMalignant labelled malignantCorrect high-risk flag in this dataset
False negativeMalignant labelled benignPotentially missed malignant example
False positiveBenign labelled malignantUnnecessary concern/follow-up if misused
True negativeBenign labelled benignCorrect benign classification
Essential habit: Never discuss sensitivity, false negatives or “positive” results before writing down which class is encoded as 1.
04 · VALIDATION PIPELINE

Fit transformations only inside each training fold

median imputation → standard scaling
→ class-balanced logistic regression
→ malignant probability

The dataset is split into 80% development and 20% held-out test data with stratification. Five-fold stratified cross-validation runs only inside the development set. The Pipeline refits imputation, scaling and logistic regression within each training fold, preventing validation-fold statistics from entering preprocessing.

After cross-validation, the pipeline is fitted on the complete development set. The test set is then used for a final audit. In a real development plan, threshold selection and model selection must occur on development/validation data before a separately protected final evaluation.

05 · METRICS & THRESHOLD TRADE-OFFS

False-negative cost changes the operating discussion

MetricFormulaInterpretation here
Sensitivity/RecallTP / (TP + FN)Fraction of malignant examples identified
SpecificityTN / (TN + FP)Fraction of benign examples identified
PrecisionTP / (TP + FP)Fraction of malignant predictions that are malignant
F12PR / (P + R)Balance of precision and recall
ROC-AUCRanking across thresholdsDiscrimination, not an operating policy

Lowering the threshold usually raises sensitivity and false positives; raising it usually raises specificity while risking more false negatives. The code prints several thresholds and uses 0.35 only as a demonstration. A clinical operating point requires prespecified objectives, calibrated probabilities, external validation and expert/regulatory review.

06 · COMPLETE IMPLEMENTATION

Reproducible audit program

programs/medical-classification-audit.py
Loading source…

The program reports development cross-validation mean and variation, a held-out threshold table, the confusion matrix and false-negative row identifiers for review. It also lists standardized coefficients as model associations while explicitly rejecting causal interpretation.

07 · INTERACTIVE TRACING

Trace the audit boundary

  1. Define data and positive class.
  2. Protect final test rows.
  3. Design validation.
  4. Prevent preprocessing leakage.
  5. Estimate development variation.
  6. Freeze model.
  7. Open test set once.
  8. Audit failures.
Current state

Press Next to begin.

08 · TEST & ERROR ANALYSIS

Verify definitions before admiring performance

Label orientation
Confirm every original malignant label becomes 1 and benign becomes 0 before computing recall.
Confusion-matrix consistency
Verify TN + FP + FN + TP equals the held-out sample count at every threshold.
Threshold monotonicity
As the threshold rises, predicted-positive count must never increase.
Fold isolation
Confirm every scaler is fitted on its fold-training partition rather than the full development data.
False-negative review
Inspect the listed row IDs and compare their probabilities and feature ranges with correctly classified malignant cases.
09 · LIMITATIONS & CLINICAL TRANSLATION

Internal performance is only the beginning

  • The dataset is small, historical and not representative of every population or clinical workflow.
  • Random row splitting may overestimate performance when site, time or patient grouping matters.
  • Feature coefficients are unstable under correlated measurements and are not causal explanations.
  • Discrimination does not guarantee calibration or clinical utility.
  • Subgroup safety cannot be claimed without appropriate metadata and sufficient samples.

Required progression

  1. Prespecify intended use, users, population, comparator and error costs.
  2. Validate externally across sites, devices, demographics and time.
  3. Assess calibration, uncertainty, subgroup performance and failure modes.
  4. Conduct prospective workflow evaluation with clinicians and patients.
  5. Implement privacy, security, monitoring, incident response and regulatory governance.
10 · PRACTICE

Check responsible evaluation

What does recall measure in this program?

What commonly happens when the threshold decreases?

Extensions

  1. Add a calibration curve and Brier score.
  2. Use repeated nested validation for model and threshold selection.
  3. Compare logistic regression with a calibrated random forest.
  4. Create a model card and dataset datasheet.
11 · INTERVIEW PREPARATION

Discuss evidence, not only algorithms

Why is sensitivity important here?

With malignant defined positive, sensitivity directly measures how many malignant examples are detected. Its importance does not remove the need to consider specificity, downstream tests and real clinical consequences.

Why is ROC-AUC insufficient?

It summarizes ranking across thresholds but does not choose an operating point, quantify calibration or reveal the exact false negatives at deployment conditions.

Why can cross-validation still mislead?

If folds do not reflect site, patient, device or temporal structure, related or distributionally similar samples may appear on both sides and inflate expected generalization.

What is external validation?

Evaluation on data collected independently from the development source, ideally reflecting the intended population and workflow. It tests transportability, not merely repeatability.

12 · KEY TAKEAWAY

A high score is not clinical evidence by itself

Responsible medical ML begins by defining the positive class and intended use, protecting evaluation data, examining clinically meaningful errors and documenting every limitation. Translation requires independent evidence, professional oversight and governance far beyond this teaching program.