This is an evaluation lesson—not a diagnostic system
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.
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?
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.
| Outcome | Meaning | Review concern |
|---|---|---|
| True positive | Malignant labelled malignant | Correct high-risk flag in this dataset |
| False negative | Malignant labelled benign | Potentially missed malignant example |
| False positive | Benign labelled malignant | Unnecessary concern/follow-up if misused |
| True negative | Benign labelled benign | Correct benign classification |
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.
False-negative cost changes the operating discussion
| Metric | Formula | Interpretation here |
|---|---|---|
| Sensitivity/Recall | TP / (TP + FN) | Fraction of malignant examples identified |
| Specificity | TN / (TN + FP) | Fraction of benign examples identified |
| Precision | TP / (TP + FP) | Fraction of malignant predictions that are malignant |
| F1 | 2PR / (P + R) | Balance of precision and recall |
| ROC-AUC | Ranking across thresholds | Discrimination, 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.
Reproducible audit program
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.
Trace the audit boundary
- Define data and positive class.
- Protect final test rows.
- Design validation.
- Prevent preprocessing leakage.
- Estimate development variation.
- Freeze model.
- Open test set once.
- Audit failures.
Press Next to begin.
Verify definitions before admiring performance
Label orientation
Confusion-matrix consistency
Threshold monotonicity
Fold isolation
False-negative review
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
- Prespecify intended use, users, population, comparator and error costs.
- Validate externally across sites, devices, demographics and time.
- Assess calibration, uncertainty, subgroup performance and failure modes.
- Conduct prospective workflow evaluation with clinicians and patients.
- Implement privacy, security, monitoring, incident response and regulatory governance.
Check responsible evaluation
What does recall measure in this program?
What commonly happens when the threshold decreases?
Extensions
- Add a calibration curve and Brier score.
- Use repeated nested validation for model and threshold selection.
- Compare logistic regression with a calibrated random forest.
- Create a model card and dataset datasheet.
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.
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.
