← Back to list

From Chat to Classification: A KDD Mini-Demo on Breast Cancer (WDBC)

Author: Shreram Palanisamy  Stack: Python · pandas · scikit-learn · Matplotlib  Assistant: ChatGPT (GPT-5 Thinking)  Dataset: Breast…

Shreram Palanisamy · 2025-10-29 23:58 · 0 claps · 4.8 min read
#kdd #data-mining #data-science #google-colab
Open on Medium ↗
Wiki topics: LLM · Large Language Models ML · Machine Learning CRY · Crypto & Web3 LIT · Literature & Writing 🔬 · Science · General

From Chat to Classification: A KDD Mini-Demo on Breast Cancer (WDBC)

Author: Shreram Palanisamy Stack: Python · pandas · scikit-learn · Matplotlib Assistant: ChatGPT (GPT-5 Thinking) Dataset: Kaggle Breast Cancer Wisconsin (Diagnostic) (WDBC)

A compact, leakage-safe KDD workflow in Colab for the Wisconsin Breast Cancer (Diagnostic) dataset. We lock the schema (30 numeric features), make a stratified 60/20/20 split, wrap Imputer → Scaler in a ColumnTransformer, train Logistic Regression and HistGradientBoosting, tune the decision threshold on the validation PR curve, and evaluate on a held-out test set. At the chosen operating point we get F1 = 0.88 and ROC-AUC ≈ 0.995, with 0 false positives and 9 false negatives—a high-precision stance that we can shift if recall needs to dominate.

Why this walkthrough exists

Most demos stop at “fit a model, call predict at 0.5.” That’s not good enough for a binary medical screen where false negatives are costly and false positives create unnecessary follow-ups. This piece shows a strict, stage-by-stage KDD path that’s reproducible, guards against leakage, and makes the operating point (threshold) an explicit choice—not an accident.

Data & setup (Colab)

  • Dataset: Breast Cancer Wisconsin (Diagnostic), binary classes: M=1 (malignant), B=0 (benign).
  • Location: "/content/drive/MyDrive/Breast Cancer-Dataset/data.csv".
  • Libraries: pandas, scikit-learn, matplotlib.
  • Goal: Build a fast, interpretable baseline vs. a non-linear tabular model, choose a threshold on validation using the precision–recall curve, then lock everything for test.

Repro tip: Freeze the 30 numeric features as a contract, drop id and any `Unnamed:artifacts, and map labelsdiagnosis → {B:0, M:1}`.*

The KDD map (at a glance)

  1. Selection — Choose the data, confirm target/feature scope, and note ethical constraints.
  2. Preprocessing — Make the split before fitting anything; ensure stratification and seeds.
  3. Transformation — Define train-only transforms in a Pipeline/ColumnTransformer.
  4. Data Mining — Train compact models with sane defaults; don’t tune the universe.
  5. Interpretation/Evaluation — Pick a threshold on validation, then report F1, ROC-AUC, and a confusion matrix on an untouched test set. Close with feature signals.

Stage 1 — Selection (scope, target, ethics)

We load from a single path in Drive and immediately infer the target (diagnosis) with a clean mapping (M→1, B→0). Anything that smells like an identifier (id) or autogenerated junk (Unnamed: 32) is dropped before modeling. We keep only numeric predictors to mirror the canonical WDBC schema (30 features).

Ethical baseline: prioritize catching malignancies (false negatives are worse than false positives), acknowledge dataset provenance/limitations, and don’t overclaim clinical utility. This is a modeling demo, not a diagnostic tool.

Stage 2 — Preprocessing (splits that don’t lie)

A split is where many demos quietly leak. We fix a random seed and do a stratified 60/20/20 (train/val/test). Why not 70/15/15? Because small validation/test sets are volatile — F1 and AUC swings from a single mistake are larger. The extra stability matters more than the small drop in training rows for the simple models we’re using.

Stratified split & class balance

Stratified split & class balance

Stage 3 — Transformation (train-only, reproducible)

We standardize the numeric features but learn all parameters on train only:

  • SimpleImputer(strategy="median") for robustness and no NaNs.
  • StandardScaler() so LR behaves and trees aren’t harmed.
  • Both inside a ColumnTransformer over the frozen feature list.

The result: same transforms for both models, and no leakage from val/test.

Shape checks; no NaNs

Shape checks; no NaNs

Stage 4 — Data Mining (baselines that bite)

Two pipelines share the same preprocessor:

  • Logistic Regression — fast, transparent, surprisingly strong on tabular.
  • HistGradientBoosting — modern tree booster for non-linear interactions.

No fishing expeditions with giant search spaces. The twist: we don’t use 0.5. Instead, we tune the decision threshold on the validation precision–recall curve to maximize F1. If multiple thresholds tie, we prefer the one with higher recall — a nod to the medical context.

PR-tuned validation results; LR wins

PR-tuned validation results; LR wins

Why threshold tuning matters Probability ranking quality (AUC) and operating point are different concepts. AUC says “you can rank benign vs. malignant well.” The threshold says “here’s how you’ll trade off FPs and FNs.” For screening, you often push recall up (catch more positives) and accept some precision loss — or do the reverse when over-referrals are a problem. The key is that the choice is deliberate.

Stage 5 — Interpretation & Evaluation (no peeking)

We freeze the winning model and the validation-derived threshold, then evaluate on the held-out test set exactly once. We report F1, ROC-AUC, a confusion matrix, and a quick feature readout:

  • If LR wins: show top coefficients by magnitude.
  • If HGB wins: show permutation importances.

Test metrics and top coefficients

Test metrics and top coefficients

Confusion matrix heatmap at the tuned threshold

Confusion matrix heatmap at the tuned threshold

What the model learned (and didn’t)

The strongest signals are consistent with the literature: morphology “worst” measurements (e.g., radius_worst, perimeter_worst, area_worst) and concavity/texture measures. LR exposes directionality via coefficients; HGB surfaces non-linear mixes. That’s helpful for sanity checks and feature QA—if your top signals aren’t in that neighborhood, revisit preprocessing and schema.

But remember: great AUC doesn’t mean perfect decisions. With the chosen threshold we favored precision (0 FPs) and accepted 9 FNs. If you’re triaging patients, you may want to swing the threshold toward higher recall and accept more FPs. Tools should fit policy, not the other way around.

Reproducibility & governance (boring, essential)

  • Seeds everywhere. Fix random_state for splits and models.
  • Schema contract. Pin the exact 30 feature names; fail fast if they drift.
  • No leakage. All transforms are fit on train only in the pipeline.
  • Single source of truth. One CSV path; avoid silent version drift.
  • Store indices. If this goes into a report or a paper, save the train/val/test row indices to re-create splits exactly.
  • Calibration check. If decision thresholds feel unstable, look at calibration; consider CalibratedClassifierCV for anything downstream of probability cutoffs.

If recall must dominate (cost-aware tweaks)

  • Optimize Fβ with β > 1 on validation (e.g., β=2) to favor recall explicitly.
  • Or impose a recall floor (e.g., ≥95%) and pick the highest precision threshold that respects it.
  • Add bootstrap CIs for F1 and AUC so you don’t chase noise.
  • If you need interpretable guardrails, train LR, then backstop it with an “override” rule (e.g., auto-flag extreme feature ranges).

Limitations & disclaimers

  • This is a modeling demo, not clinical guidance. Dataset bias and collection context matter.
  • We didn’t do heavy hyper-parameter tuning, subgroup fairness analysis, or prospective validation.
  • Metrics on a single test split are still finite-sample estimates — treat them with caution.

메타데이터
post_id
e2f47c524114
slug
from-chat-to-classification-a-kdd-mini-demo-on-breast-cancer-wdbc-e2f47c524114
url
https://medium.com/@shrerampalanisamy/from-chat-to-classification-a-kdd-mini-demo-on-breast-cancer-wdbc-e2f47c524114
canonical_url
https://medium.com/@shrerampalanisamy/from-chat-to-classification-a-kdd-mini-demo-on-breast-cancer-wdbc-e2f47c524114
author_url
https://medium.com/@shrerampalanisamy
status
ok
fetched_at
2026-06-13 09:11:36