DULUTH, MN MANILA, PH
Say hello

Part 2 — Graphs & Machine Learning Chapters 5–7

Graphs & Machine Learning: Finding Structure and Making Predictions

Graph search (BFS/DFS)Shortest pathPageRankClusteringPCARegressionDecision treesGradient boosting

Study notes I'm keeping as I learn to program. The ideas here come from Imran Ahmad's 50 Algorithms Every Programmer Should Know — I'm sharing them in my own words. The plain-language explanations, the examples, and any mistakes are mine.

The concept in plain language

Two big ideas live in this part, and they fit together.

The first is the graph — not a bar chart, but a web of things (called nodes) joined by relationships (called edges). Cities joined by roads. Web pages joined by links. Patients joined to compatible donors. Once you draw your problem as a graph, a small family of algorithms can walk it. Breadth-first search explores outward one ring at a time, like ripples in a pond — good for “what’s the fewest hops to get there.” Depth-first search plunges down one path to the end before backing up — good for “is there any way through at all.” And when the edges have a cost — miles, minutes, dollars — shortest-path algorithms find the cheapest route. The punchline: most “find the best connection” problems are secretly the same problem.

Shortest path through a weighted graphSix nodes A to F joined by weighted edges. The cheapest route from A to F is highlighted, summing the smallest total edge cost rather than the fewest hops.25173241ABCDEF
A weighted graph. Numbers are edge costs (miles, minutes, dollars). The highlighted route is the cheapest from A to F — what Dijkstra's algorithm finds, and what your maps app runs billions of times a day.

The second idea is machine learning — letting a program find the pattern instead of hand-writing the rule. It splits into two camps. Unsupervised learning gets unlabeled data and hunts for structure: clustering (k-means, hierarchical, DBSCAN) sorts examples into natural groups nobody named in advance, and PCA (principal component analysis) squeezes dozens of measurements down to the two or three that carry most of the signal, so you can actually see it. Supervised learning gets examples with the answer attached and learns to predict the answer on new cases: logistic regression for yes/no odds, decision trees for a flowchart of if-then splits, and ensembles like random forests and gradient boosting that combine hundreds of weak trees into one strong predictor.

k-means clustering into three groupsA scatter of points falls into three natural groups; each group's centroid is marked with a cross and ring. No labels were given in advance.
k-means sorts unlabeled points into groups nobody named in advance — each cross is a cluster's centre. This is how sepsis phenotypes were discovered: patients grouped by their own data, not by a rule.

The mental model to keep: a graph is a map of how things connect, and machine learning is a machine for turning examples into predictions. Neither one is magic. Both are just bookkeeping done carefully at scale.

Where you’ve seen it in the real world

Every time your phone reroutes you around traffic, you are watching a shortest-path algorithm run. The ancestor of that feature is a single 1959 paper by Edsger Dijkstra, A Note on Two Problems in Connexion with Graphs, three pages long, that described how to find the cheapest route through a weighted graph. By his own account he worked the idea out in his head in about twenty minutes at a café, a few years before he wrote it down. Sixty-some years later it runs billions of times a day inside mapping apps.

Google itself began as a graph algorithm. In their 1998 paper The Anatomy of a Large-Scale Hypertextual Web Search Engine, Sergey Brin and Larry Page treated the web as one giant graph and ranked pages by PageRank — a page is important if important pages link to it. That circular idea, computed over the whole link graph, was the difference between useful search and noise.

On the machine-learning side, spam is the classic story. In August 2002 Paul Graham published A Plan for Spam, arguing that instead of hand-writing rules, you should train a naive Bayes classifier on your own mail — count which words show up in spam versus real email, then combine the fifteen most telling tokens with Bayes’ rule. He reported his filter missing fewer than 5 spams per 1,000 with zero false positives. That essay kicked off the statistical spam filtering the whole industry adopted.

And when it comes to structured prediction — the tabular, spreadsheet-shaped data most of business and medicine actually lives in — one tool dominates. In the 2016 paper XGBoost: A Scalable Tree Boosting System, Tianqi Chen and Carlos Guestrin reported that of the 29 challenge-winning solutions published on Kaggle’s blog during 2015, 17 used XGBoost — gradient-boosted decision trees. Not a neural network. Hundreds of small trees, each fixing the last one’s mistakes.

The healthcare angle

These same tools quietly run through medicine, often decades before anyone called it “AI.”

Start with graphs. Kidney paired donation is a graph-matching problem. You have willing donors who don’t match their intended recipient; draw an edge wherever donor A matches recipient B, and the job is to find cycles and chains that let everyone get a compatible organ. This is exactly the market-design work that earned Alvin Roth (with Lloyd Shapley) the 2012 Nobel Prize in Economics. It is not abstract: the New England Journal of Medicine documented a nonsimultaneous, extended, altruistic-donor chain in which one altruistic donor kicked off a chain that transplanted ten recipients. That is a matching search over a compatibility graph, saving real lives.

Now clustering. In 2019, Seymour and colleagues published their work on novel clinical phenotypes for sepsis in JAMA. Using k-means clustering across three cohorts totaling 63,858 patients, they derived and validated four reproducible sepsis phenotypes — labeled α, β, γ, and δ — that differed in lab values, organ dysfunction, and mortality. Nobody defined those four groups in advance; the algorithm surfaced them. The provocative part: in re-analyses of clinical-trial data, the mix of phenotypes changed whether a treatment looked helpful or harmful. Sepsis may not be one disease we keep failing to treat, but several diseases wearing the same name.

PCA earns a beautiful non-clinical demonstration too. In 2008, Novembre and colleagues genotyped around 3,000 Europeans at about half a million DNA sites, then ran PCA on the genomes of the roughly 1,400 individuals who passed quality filters. The top two components — the two axes that captured the most variation — reconstructed a recognizable map of Europe. Plot each person by their genetic coordinates and you get the geography back, close enough that half of them landed within about 310 kilometers of home. Genes mirror geography, and PCA is what let us see it.

Finally, supervised prediction. Long before machine learning was fashionable, cardiology built a working clinical predictor with plain regression. The Framingham risk score, published by Wilson and colleagues in Circulation in 1998, used sex-specific proportional-hazards regression to turn age, cholesterol, blood pressure, smoking, and diabetes into a personalized 10-year risk of coronary heart disease. That is textbook supervised learning — inputs in, calibrated risk out — sitting in clinical guidelines for a generation.

Why it matters when you work with AI

Three things stick with me as a physician learning to build.

First, most hard problems are old problems in a new coat. Routing, ranking, matching, and risk-scoring are graph and regression problems we have understood for decades. When a vendor pitches “AI” for care coordination, the honest question is often just: what’s the graph, and what’s the objective?

Second, the boring model usually wins on tabular data. Gradient-boosted trees, not deep networks, dominate structured prediction — as XGBoost’s Kaggle record shows. For most clinical spreadsheets, reaching for a neural network first is a tell that someone likes the tool more than the problem.

Third, unsupervised methods find structure, not truth. k-means will hand you four sepsis clusters whether or not four is the right number; PCA will draw axes whether or not they mean anything. The sepsis phenotypes are compelling because they were validated and tied to outcomes — not because the algorithm produced them. That discipline, verify before you believe, is the same one I use at the bedside, and it’s exactly the habit that keeps machine learning honest.

Sources

  1. Dijkstra, E.W., A Note on Two Problems in Connexion with Graphs (1959) — Numerische Mathematik
  2. Brin, S. & Page, L., The Anatomy of a Large-Scale Hypertextual Web Search Engine (1998) — Stanford InfoLab / Google Research
  3. Graham, P., A Plan for Spam (2002) — paulgraham.com
  4. Chen, T. & Guestrin, C., XGBoost: A Scalable Tree Boosting System (2016) — KDD 2016
  5. Chen, T. & Guestrin, C., XGBoost preprint (2016) — arXiv
  6. Novembre, J. et al., Genes Mirror Geography Within Europe (2008) — Nature
  7. Novembre, J. et al., Genes Mirror Geography Within Europe (2008) — open full text, PMC
  8. The Sveriges Riksbank Prize in Economic Sciences 2012 (Roth & Shapley) — NobelPrize.org
  9. Rees, M.A. et al., A Nonsimultaneous, Extended, Altruistic-Donor Chain (2009) — New England Journal of Medicine
  10. Seymour, C.W. et al., Derivation, Validation, and Potential Treatment Implications of Novel Clinical Phenotypes for Sepsis (2019) — JAMA (open full text, PMC)
  11. Wilson, P.W.F. et al., Prediction of Coronary Heart Disease Using Risk Factor Categories (1998) — Circulation

— Jeremy Tabernero, MD · More in this series · Get in touch