<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Lambert Leong</title>
    <description>Health AI portfolio for Lambert Leong, PhD</description>
    <link>https://www.lambertleong.com/</link>
    <atom:link href="https://www.lambertleong.com/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Fri, 05 Jun 2026 05:04:41 +0000</pubDate>
    <lastBuildDate>Fri, 05 Jun 2026 05:04:41 +0000</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
      <item>
        <title>Agents Under the Curve (AUC)</title>
        <description>&lt;h2 id=&quot;tldr&quot;&gt;TLDR&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Agentic AI systems in healthcare often output binary decisions such as disease or no disease, which by themselves cannot produce a meaningful AUC.&lt;/li&gt;
  &lt;li&gt;AUC is still the standard way to compare risk and detection models in medicine, and it requires continuous scores that let us rank patients by risk.&lt;/li&gt;
  &lt;li&gt;This post describes several practical strategies for converting agentic outputs into continuous scores so that AUC based comparisons with traditional models remain valid and fair.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;contents&quot;&gt;Contents&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#head-intro&quot;&gt;Agent and Area Under the Curve Disconnect&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-whyauc&quot;&gt;Why AUC Matters and Why Binary Outputs Fail&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-table&quot;&gt;Comparison Table&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-methods&quot;&gt;Methods To Derive Continuous Scores&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-final&quot;&gt;Final Thoughts&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#resources&quot;&gt;More Relevant Resources&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;agent-and-area-under-the-curve-disconnect-&quot;&gt;Agent and Area Under the Curve Disconnect &lt;a name=&quot;head-intro&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;Agentic AI systems are becoming increasingly common as they lower the barrier to entry for AI solutions. They accomplish this by leveraging foundational models so that resources do not always need to be spent on training a custom model from the ground up or on multiple rounds of fine-tuning.&lt;/p&gt;

&lt;p&gt;I noticed that roughly 20 - 25% of the papers at NeurIPS 2025 were focused on agentic solutions. Agents for medical applications are rising in parallel and gaining popularity. These systems include LLM driven pipelines, retrieval augmented agents, and multi step decision frameworks. They can synthesize heterogeneous data, reason step-by-step, and produce contextual recommendations or decisions.&lt;/p&gt;

&lt;p&gt;Most of these systems are built to answer questions like “Does this patient have the disease” or “Should we order this test” instead of “What is the probability that this patient has the disease.” In other words, they tend to produce hard decisions and explanations, not calibrated probabilities.&lt;/p&gt;

&lt;p&gt;In contrast, traditional medical risk and detection models are usually evaluated with the area under the receiver operating characteristic curve or AUC. AUC is deeply embedded in clinical prediction work and is the default metric for comparing models in many imaging, risk, and screening studies.&lt;/p&gt;

&lt;p&gt;This creates a gap. If our new models are agentic and decision focused, but our evaluation standards are probability based, we need methods that connect the two. The rest of this post focuses on what AUC actually needs, why binary outputs are not enough, and how to derive continuous scores from agentic frameworks so that AUC remains usable.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;why-auc-matters-and-why-binary-outputs-fail-&quot;&gt;Why AUC Matters and Why Binary Outputs Fail &lt;a name=&quot;head-whyauc&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;AUC is often considered the gold standard metric in medical applications because it handles the imbalance between cases and controls better than simple accuracy, especially in datasets that reflect real world prevalence.&lt;/p&gt;

&lt;p&gt;Accuracy can be a misleading metric when disease prevalence is low. For example, breast cancer prevalence in a screening population is roughly 5 in 1000. A model that predicts “no cancer” for every case would still have very high accuracy, but the false negative rate would be unacceptably high. In a real clinical context, this is clearly a bad model, despite its accuracy.&lt;/p&gt;

&lt;p&gt;AUC measures how well a model separates positive cases from negative cases. It does this by looking at a continuous score for each individual and asking how well these scores rank positives above negatives. This ranking based view is why AUC remains useful even when classes are highly imbalanced.&lt;/p&gt;

&lt;p&gt;While I noticed great innovative work at the intersection of agents and health at NeurIPS, I did not see many papers that reported an AUC. I also did not see many that compared a new agentic approach to an existing or established conventional machine learning or deep learning model using standard metrics. Without this, it is difficult to calibrate and understand how much better these agentic solutions actually are, if at all.&lt;/p&gt;

&lt;p&gt;Most current agentic outputs do not lend themselves naturally to obtaining AUCs. With this article, the goal is to propose methods to obtain AUC for agentic systems so that we can start a concrete conversation about performance gains compared to previous and existing solutions.&lt;/p&gt;

&lt;h4 id=&quot;how-auc-is-computed&quot;&gt;How AUC is computed&lt;/h4&gt;

&lt;p&gt;To fully understand the gap and appreciate attempts at a solution, we should review how AUCs are calculated.&lt;/p&gt;

&lt;p&gt;Let&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;i&gt;y&lt;/i&gt; &amp;in; {0, 1} be the true label&lt;/li&gt;
  &lt;li&gt;&lt;i&gt;s&lt;/i&gt; &amp;in; &amp;#8477; be the model score for each individual&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The ROC curve is built by sweeping a threshold &lt;i&gt;t&lt;/i&gt; across the full range of scores and computing&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Sensitivity at each threshold&lt;/li&gt;
  &lt;li&gt;Specificity at each threshold&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AUC can then be interpreted as&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The probability that a randomly selected positive case has a higher score than a randomly selected negative case.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This interpretation only makes sense if the scores contain enough granularity to induce a ranking across individuals. In practice, that means we need continuous or at least finely ordered values, not just zeros and ones.&lt;/p&gt;

&lt;h4 id=&quot;why-binary-agentic-outputs-break-auc&quot;&gt;Why binary agentic outputs break AUC&lt;/h4&gt;

&lt;p&gt;Agentic systems often output only a binary decision. For example:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;“disease” mapped to 1&lt;/li&gt;
  &lt;li&gt;“no disease” mapped to 0&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If these are the only possible outputs, then there are only two unique scores. When we sweep thresholds over this set, the ROC curve collapses to at most one nontrivial point plus the trivial endpoints. There is no rich set of thresholds and no meaningful ranking.&lt;/p&gt;

&lt;p&gt;In this case, the AUC becomes either undefined or degenerate. It also cannot be fairly compared to AUC values from traditional models that output continuous probabilities.&lt;/p&gt;

&lt;div style=&quot;text-align: center;&quot;&gt;
  &lt;a name=&quot;img-auc-collapse&quot;&gt;&lt;/a&gt;
  &lt;img src=&quot;/assets/images/essays/agent-auc/degenerate_roc_watermarked.png&quot; style=&quot;width: 69%;&quot; alt=&quot;Diagram showing how binary outputs collapse the ROC curve compared to continuous scores&quot; /&gt;
  &lt;br /&gt;
  &lt;span style=&quot;font-style: italic; font-size: 0.9em;&quot;&gt;Figure 1: Visualizing why binary outputs lead to ROC curve issues.&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;To evaluate agentic solutions using AUC, we must create a continuous score that captures how strongly the agent believes that a case is positive.&lt;/p&gt;

&lt;h4 id=&quot;what-we-need&quot;&gt;What we need&lt;/h4&gt;

&lt;p&gt;To compute an AUC for an agentic system, we need a continuous score that reflects its underlying risk assessment, confidence, or ranking. The score does not have to be a perfectly calibrated probability. It only needs to provide an ordering across patients that is consistent with the agent’s internal notion of risk.&lt;/p&gt;

&lt;p&gt;Below is a list of practical strategies for transforming agentic outputs into such scores.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;methods-to-derive-continuous-scores-from-agentic-systems-&quot;&gt;Methods To Derive Continuous Scores From Agentic Systems &lt;a name=&quot;head-methods&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Extract internal model log probabilities.&lt;/li&gt;
  &lt;li&gt;Ask the agent to output an explicit probability.&lt;/li&gt;
  &lt;li&gt;Use Monte Carlo repeated sampling to estimate a probability.&lt;/li&gt;
  &lt;li&gt;Convert retrieval similarity scores into risk scores.&lt;/li&gt;
  &lt;li&gt;Train a calibration model on top of agent outputs.&lt;/li&gt;
  &lt;li&gt;Sweep a tunable threshold or configuration inside the agent to approximate an ROC curve.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;comparison-table-&quot;&gt;Comparison Table &lt;a name=&quot;head-table&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;style&gt;
.comparison-table {
  overflow-x: auto;
  margin: 2rem 0;
}
.comparison-table table {
  width: 100%;
  border-collapse: collapse;
}
.comparison-table th,
.comparison-table td {
  padding: 12px;
  text-align: left;
  border: 1px solid #ddd;
  vertical-align: top;
}
.comparison-table th {
  background-color: #f5f5f5;
  font-weight: bold;
}
&lt;/style&gt;

&lt;div class=&quot;comparison-table&quot;&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Log probabilities&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Continuous, stable signal that aligns with model reasoning and ranking&lt;/td&gt;
&lt;td&gt;Requires access to logits and can be sensitive to prompt format&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Explicit probability output&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Simple, intuitive, and easy to communicate to clinicians and reviewers&lt;/td&gt;
&lt;td&gt;Calibration quality depends on prompting and model behavior&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Monte Carlo sampling&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Captures the agent&apos;s true decision uncertainty without internal access&lt;/td&gt;
&lt;td&gt;Computationally more expensive and requires multiple runs per patient&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Retrieval similarity&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Ideal for retrieval-based systems and straightforward to compute&lt;/td&gt;
&lt;td&gt;May not fully reflect downstream decision logic or overall reasoning&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Calibration model&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Converts structured or categorical outputs into smooth risk scores and can improve calibration&lt;/td&gt;
&lt;td&gt;Requires labeled data and adds a secondary model to the pipeline&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Threshold sweeping&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Works even when the agent only exposes binary outputs and a tunable parameter&lt;/td&gt;
&lt;td&gt;Produces an approximate AUC that depends on how the parameter affects decisions&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;In the next section, each method is described in more detail, including why it works, when it is most appropriate, and what limitations to keep in mind.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;method-1-extract-internal-model-log-probabilities-&quot;&gt;Method 1. Extract internal model log probabilities &lt;a name=&quot;head-m1&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h4 id=&quot;concept&quot;&gt;Concept&lt;/h4&gt;

&lt;p&gt;Many agentic systems rely on a large language model or other differentiable model internally. During decoding, these models compute token level log probabilities. Even if the final output is a binary label, the model still evaluates how likely each option is.&lt;/p&gt;

&lt;p&gt;If the agent decides between “disease” and “no disease” as its final outcome, we can extract:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;log &lt;i&gt;p&lt;/i&gt;(disease)&lt;/li&gt;
  &lt;li&gt;log &lt;i&gt;p&lt;/i&gt;(no disease)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and define a continuous score such as:&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 1em 0;&quot;&gt;
  &lt;i&gt;s&lt;/i&gt; = log &lt;i&gt;p&lt;/i&gt;(disease) &amp;minus; log &lt;i&gt;p&lt;/i&gt;(no disease)
&lt;/div&gt;

&lt;p&gt;This score is higher when the model favors the disease label and lower when it favors the no disease label.&lt;/p&gt;

&lt;h4 id=&quot;why-this-works&quot;&gt;Why this works&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Log probabilities are continuous and provide a smooth ranking signal.&lt;/li&gt;
  &lt;li&gt;They directly encode the model’s preference between outcomes.&lt;/li&gt;
  &lt;li&gt;They are a natural fit for ROC analysis, since AUC only needs ranking, not perfect calibration.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;best-for&quot;&gt;Best for&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Agentic frameworks that are clearly LLM based.&lt;/li&gt;
  &lt;li&gt;Situations where you have access to token level log probabilities through the model or API.&lt;/li&gt;
  &lt;li&gt;Experiments where you care about precise ranking quality.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;caution&quot;&gt;Caution&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Not all APIs expose log probabilities.&lt;/li&gt;
  &lt;li&gt;The values can be sensitive to prompt formatting and output template choices, so it is important to keep these consistent across patients and models.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;method-2-ask-the-agent-to-output-a-probability-&quot;&gt;Method 2. Ask the agent to output a probability &lt;a name=&quot;head-m2&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h4 id=&quot;concept-1&quot;&gt;Concept&lt;/h4&gt;

&lt;p&gt;If the agent already produces step by step reasoning, we can extend the final step to include an estimated probability. For example, you can instruct the system:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;After completing your reasoning, output a line of the form:&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;risk_probability: &amp;lt;value between 0 and 1&amp;gt;&lt;/code&gt;&lt;br /&gt;
that represents the probability that this patient has or will develop the disease.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The numeric value in this line becomes the continuous score.&lt;/p&gt;

&lt;h4 id=&quot;why-this-works-1&quot;&gt;Why this works&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;It generates a direct continuous scalar output for each patient.&lt;/li&gt;
  &lt;li&gt;It does not require low level access to logits or internal layers.&lt;/li&gt;
  &lt;li&gt;It is easy to explain to clinicians, collaborators, or reviewers who expect a numeric probability.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;best-for-1&quot;&gt;Best for&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Evaluation pipelines where interpretability and communication are important.&lt;/li&gt;
  &lt;li&gt;Settings where you can modify prompts but not the underlying model internals.&lt;/li&gt;
  &lt;li&gt;Early stage experiments and prototypes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;caution-1&quot;&gt;Caution&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;The returned probability may not be well calibrated without further adjustment.&lt;/li&gt;
  &lt;li&gt;Small prompt changes can shift the distribution of probabilities, so prompt design should be fixed before serious evaluation.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;method-3-use-monte-carlo-repeated-sampling-&quot;&gt;Method 3. Use Monte Carlo repeated sampling &lt;a name=&quot;head-m3&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h4 id=&quot;concept-2&quot;&gt;Concept&lt;/h4&gt;

&lt;p&gt;Many agentic systems use stochastic sampling when they reason, retrieve information, or generate text. This randomness can be exploited to estimate an empirical probability.&lt;/p&gt;

&lt;p&gt;For each patient:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Run the agent on the same input N times.&lt;/li&gt;
  &lt;li&gt;Count how many times it predicts disease.&lt;/li&gt;
  &lt;li&gt;Define the score as&lt;/li&gt;
&lt;/ol&gt;

&lt;div style=&quot;text-align: center; margin: 1em 0;&quot;&gt;
  &lt;i&gt;s&lt;/i&gt; = (number of disease predictions) / &lt;i&gt;N&lt;/i&gt;
&lt;/div&gt;

&lt;p&gt;This frequency behaves like an estimated probability of disease according to the agent.&lt;/p&gt;

&lt;h4 id=&quot;why-this-works-2&quot;&gt;Why this works&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;It turns discrete yes or no predictions into a continuous probability estimate.&lt;/li&gt;
  &lt;li&gt;It captures the agent’s internal uncertainty, as reflected in its sampling behavior.&lt;/li&gt;
  &lt;li&gt;It does not require log probabilities or special access to the model.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;best-for-2&quot;&gt;Best for&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Stochastic LLM agents that produce different outputs when you change the random seed or temperature.&lt;/li&gt;
  &lt;li&gt;Agentic pipelines that incorporate random choices in retrieval or planning.&lt;/li&gt;
  &lt;li&gt;Scenarios where you want a conceptually simple probability estimate.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;caution-2&quot;&gt;Caution&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Running N repeated inferences per patient increases computation time.&lt;/li&gt;
  &lt;li&gt;The variance of the estimate decreases with N, so you need to choose N large enough for stability but small enough to stay efficient.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;method-4-convert-retrieval-similarity-scores-into-risk-scores-&quot;&gt;Method 4. Convert retrieval similarity scores into risk scores &lt;a name=&quot;head-m4&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h4 id=&quot;concept-3&quot;&gt;Concept&lt;/h4&gt;

&lt;p&gt;Retrieval augmented agents typically query a vector database of past patients, clinical notes, or imaging derived embeddings. The retrieval stage produces similarity scores between the current patient and stored exemplars.&lt;/p&gt;

&lt;p&gt;If you have a set of high risk or positive exemplars, you can define a score such as&lt;/p&gt;

&lt;div style=&quot;text-align: center; margin: 1em 0;&quot;&gt;
  &lt;i&gt;s&lt;/i&gt; = max&lt;sub&gt;&lt;i&gt;j&lt;/i&gt;&lt;/sub&gt; similarity(&lt;i&gt;x&lt;/i&gt;, &lt;i&gt;e&lt;sub&gt;j&lt;/sub&gt;&lt;/i&gt;)
&lt;/div&gt;

&lt;p&gt;where &lt;i&gt;e&lt;sub&gt;j&lt;/sub&gt;&lt;/i&gt; indexes embeddings from known positive cases and similarity is something like cosine similarity.&lt;/p&gt;

&lt;p&gt;The more similar the patient is to previously seen positive cases, the higher the score.&lt;/p&gt;

&lt;h4 id=&quot;why-this-works-3&quot;&gt;Why this works&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Similarity scores are naturally continuous and often well structured.&lt;/li&gt;
  &lt;li&gt;Retrieval quality tends to track disease patterns if the exemplar set is chosen carefully.&lt;/li&gt;
  &lt;li&gt;The scoring step exists even if the downstream agent logic makes only a binary decision.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;best-for-3&quot;&gt;Best for&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Retrieval-augmented-generation (RAG) agents.&lt;/li&gt;
  &lt;li&gt;Systems that are explicitly prototype based.&lt;/li&gt;
  &lt;li&gt;Situations where embedding and retrieval components are already well tuned.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;caution-3&quot;&gt;Caution&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Retrieval similarity may capture only part of the reasoning that leads to the final decision.&lt;/li&gt;
  &lt;li&gt;Biases in the embedding space can distort the score distribution and should be monitored.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;method-5-train-a-calibration-model-on-top-of-agent-outputs-&quot;&gt;Method 5. Train a calibration model on top of agent outputs &lt;a name=&quot;head-m5&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h4 id=&quot;concept-4&quot;&gt;Concept&lt;/h4&gt;

&lt;p&gt;Some agentic systems output structured categories such as low, medium, or high risk, or generate explanations that follow a consistent template. These categorical or structured outputs can be converted to continuous scores using a small calibration model.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Encode categories as features.&lt;/li&gt;
  &lt;li&gt;Optionally embed textual explanations into vectors.&lt;/li&gt;
  &lt;li&gt;Train logistic regression, isotonic regression, or another simple model to map those features to a risk probability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The calibration model learns how to assign continuous scores based on how the agent’s outputs correlate with true labels.&lt;/p&gt;

&lt;h4 id=&quot;why-this-works-4&quot;&gt;Why this works&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;It converts coarse or discrete outputs into smooth, usable scores.&lt;/li&gt;
  &lt;li&gt;It can improve calibration by aligning scores with observed outcome frequencies.&lt;/li&gt;
  &lt;li&gt;It is aligned with established practice, such as mapping BI-RADS categories to breast cancer risk.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;best-for-4&quot;&gt;Best for&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Agents that output risk categories, scores on an internal scale, or structured explanations.&lt;/li&gt;
  &lt;li&gt;Clinical workflows where calibrated probabilities are needed for decision support or shared decision making.&lt;/li&gt;
  &lt;li&gt;Settings where labeled outcome data is available for fitting the calibration model.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;caution-4&quot;&gt;Caution&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;This approach introduces a second model that must be documented and maintained.&lt;/li&gt;
  &lt;li&gt;It requires enough labeled data to train and validate the calibration step.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;method-6-sweep-a-tunable-threshold-or-configuration-inside-the-agent-&quot;&gt;Method 6. Sweep a tunable threshold or configuration inside the agent &lt;a name=&quot;head-m6&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h4 id=&quot;concept-5&quot;&gt;Concept&lt;/h4&gt;

&lt;p&gt;Some agentic systems expose configuration parameters that control how aggressive or conservative they are. Examples include:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A sensitivity or risk tolerance setting.&lt;/li&gt;
  &lt;li&gt;The number of retrieved documents.&lt;/li&gt;
  &lt;li&gt;The number of reasoning steps to perform before making a decision.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the agent remains strictly binary at each setting, you can treat the configuration parameter as a pseudo threshold:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Choose several parameter values that range from conservative to aggressive.&lt;/li&gt;
  &lt;li&gt;For each value, run the agent on all patients and record sensitivity and specificity.&lt;/li&gt;
  &lt;li&gt;Plot these operating points to form an approximate ROC curve.&lt;/li&gt;
  &lt;li&gt;Compute the area under this curve as an approximate AUC.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;why-this-works-5&quot;&gt;Why this works&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;It converts a rigid binary decision system into a collection of operating points.&lt;/li&gt;
  &lt;li&gt;The resulting curve can be interpreted similarly to a traditional ROC curve, although the x axis is controlled indirectly through the configuration parameter rather than a direct score threshold.&lt;/li&gt;
  &lt;li&gt;It is reminiscent of decision curve analysis, which also examines performance across a range of decision thresholds.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;best-for-5&quot;&gt;Best for&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Rule based or deterministic agents with tunable configuration parameters.&lt;/li&gt;
  &lt;li&gt;Systems where probabilities and logits are inaccessible.&lt;/li&gt;
  &lt;li&gt;Scenarios where you care about trade offs between sensitivity and specificity at different operating modes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;caution-5&quot;&gt;Caution&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;The resulting AUC is approximate and based on parameter sweeps rather than direct score thresholds.&lt;/li&gt;
  &lt;li&gt;Interpretation depends on understanding how the parameter affects the underlying decision logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;final-thoughts-&quot;&gt;Final Thoughts &lt;a name=&quot;head-final&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;Agentic systems are becoming central to AI including medical use cases, but their tendency to output hard decisions conflicts with how we traditionally evaluate risk and detection models. AUC is still a standard reference point in many clinical and research settings, and AUC requires continuous scores that allow meaningful ranking of patients.&lt;/p&gt;

&lt;p&gt;The methods in this post provide practical ways to bridge the gap. By extracting log probabilities, asking the agent for explicit probabilities, using repeated sampling, exploiting retrieval similarity, training a small calibration model, or sweeping configuration thresholds, we can construct continuous scores that respect the agent’s internal behavior and still support rigorous AUC based comparisons.&lt;/p&gt;

&lt;p&gt;This keeps new agentic solutions grounded against established baselines and allows us to evaluate them using the same language and methods that clinicians, statisticians, and reviewers already understand. With an AUC, we can truly evaluate if the agentic system is adding value.&lt;/p&gt;

&lt;h3 id=&quot;relevant-resources-&quot;&gt;Relevant Resources &lt;a name=&quot;resources&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.lambertleong.com/thoughts/auc-idi-nri&quot;&gt;Area Under the Curve and Beyond with Integrated Discrimination Improvement and Net Reclassification&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.lambertleong.com/projects/deep-learning-breast-cancer-risk&quot;&gt;Using AUC in Medicine with Deep Learning&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Sat, 20 Dec 2025 00:00:00 +0000</pubDate>
        <link>https://www.lambertleong.com/thoughts/agentic-auc</link>
        <guid isPermaLink="true">https://www.lambertleong.com/thoughts/agentic-auc</guid>
        
        <category>AUC</category>
        
        <category>ROC</category>
        
        <category>agentic\</category>
        
        <category>AI</category>
        
        <category>medical\</category>
        
        <category>AI</category>
        
        <category>risk\</category>
        
        <category>prediction</category>
        
        <category>area\</category>
        
        <category>under\</category>
        
        <category>the\</category>
        
        <category>curve</category>
        
        <category>model\</category>
        
        <category>evaluation</category>
        
        <category>disease\</category>
        
        <category>risk</category>
        
        <category>binary\</category>
        
        <category>classification</category>
        
        
        <category>thoughts</category>
        
      </item>
    
      <item>
        <title>AI Predicts Your Insides From Your Outsides With Pseudo-DXA</title>
        <description>&lt;h1 id=&quot;ai-predicts-your-insides-from-your-outsides-with-pseudo-dxa&quot;&gt;AI Predicts Your Insides From Your Outsides With Pseudo-DXA&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;A Quantitatively Accurate and Clinically Useful Generative Medical Imaging Model&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;key-points&quot;&gt;Key Points&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Quantitative Accuracy&lt;/strong&gt;: To our knowledge, this is the first quantitatively accurate model in which generated medical imaging can be analyzed with commercial clinical software.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Predictive Power&lt;/strong&gt;: Being able to predict interior distributions of fat, muscle, and bone from exterior shape indicates the strong relationship between body composition and body shape.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Accessibility and Safety&lt;/strong&gt;: This model represents a significant step towards accessible health monitoring, producing images that would normally require specialized, expensive equipment, trained technicians, and involve exposure to potentially harmful ionizing radiation.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.nature.com/articles/s43856-024-00434-w&quot;&gt;Read the paper here&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Generative artificial intelligence (AI) has become astonishingly popular especially after the release of both diffusion models like DALL-E and large language models (LLM) like ChatGPT. In general, AI models are classified as “generative” when the model produces something as an output. For DALL-E the product output is a high-quality image while for ChatGPT the product or output is highly structured meaningful text. These generative models are different than classification models that output a prediction for one side of a decision boundary such as cancer or no cancer and these are also different from regression models that output numerical predictions such as blood glucose level. Medical imaging and healthcare have benefited from AI in general and several compelling use cases and generative models are constantly being developed. A major barrier to clinical use of generative AI models is a lack of validation of model outputs beyond just image quality assessments. In our work, we evaluate our generative model on both a qualitative and quantitative assessment as a step towards more clinically relevant AI models.both a qualitative and quantitative assessment as a step towards more clinically relevant AI models.&lt;/p&gt;

&lt;h2 id=&quot;quality-vs-quantity&quot;&gt;Quality vs Quantity&lt;/h2&gt;
&lt;p&gt;In medical imaging, image quality is crucial; it’s all about how well the image represents the internal structures of the body. The majority of the use cases for medical imaging is predicated on having images of high quality. For instance, X-ray scans use ionizing radiation to produce images of many internal structures of the body and quality is important for identifying bone from soft tissue or organs as well as identifying anomalies like tumors. High quality X-ray images result in easier to identify structures which can translate to more accurate diagnosis. Computer vision research has led to the development of metrics meant to objectively measure image quality. These metrics, which we use in our work, include peak signal to noise ratio (PSNR) and structural similarity index (SSIM), for example. Ultimately, a high-quality image can be defined as having sharp, well defined borders, with good contrast between different anatomical structures.&lt;/p&gt;

&lt;p&gt;Images are highly structured data types and made up of a matrix of pixels of varying intensities. Unlike natural images as seen in the ImageNet dataset consisting of cars, planes, boats, and etc. which have three red, green, and blue color channels, medical images are mostly gray scale or a single channel. Simply put, sharp edges are achieved by having pixels near the borders of structures be uniform and good contrast is achieved when neighboring pixels depicting different structures have a noticeable difference in value from one another. It is important to note that the absolute value of the pixels are not the most important thing for high quality images and it is in fact more dependent on the relative pixel intensities to each other. This, however, is not the case for achieving images with high quantitative accuracy.&lt;/p&gt;

&lt;div style=&quot;text-align: center;&quot;&gt;
  &lt;a name=&quot;img-subsection&quot;&gt;&lt;/a&gt;
  &lt;img src=&quot;/assets/images/projects/pseudo_dxa/pixel_quality_vs_quantity.webp&quot; style=&quot;width: 100%;&quot; alt=&quot;Comparison of medical imaging showing High Quality, High Quantitative Accuracy versus High Quality, Low Quantitative Accuracy, alongside an Image Difference heatmap highlighting discrepancies in measurement details of bone, muscle, and fat across scans.&quot; /&gt;
  &lt;br /&gt;
  &lt;span&gt;Demonstrating the difference between quality and quantity. Both images look the same and are of good quality but the one on the right gives the right biological measurements of bone, muscle, and fat.&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;A subset of medical imaging modalities is quantitative meaning the pixel values represent a known quantity of some material or tissue. Dual energy X-ray Absorptiometry (DXA) is a well known and common quantitative imaging modality used for measuring body composition. DXA images are acquired using high and low energy X-rays. Then a set of equations sometimes refered to as DXA math is used to compute the contrast and ratios between the high and low energy X-ray images to yield quantities of fat, muscle, and bone. Hence the word quantitative. The absolute value of each pixel is important because it ultimately corresponds to a known quantity of some material. Any small changes in the pixel values, while it may still look of the same or similar quality, will result in noticeably different tissue quantities.&lt;/p&gt;

&lt;div style=&quot;text-align: center;&quot;&gt;
  &lt;a name=&quot;img-subsection&quot;&gt;&lt;/a&gt;
  &lt;img src=&quot;/assets/images/projects/pseudo_dxa/quantitative_analysis_hologic_apex.webp&quot; style=&quot;width: 100%;&quot; alt=&quot;Screenshot of a Hologic QDR Workstation displaying a whole body DXA scan with detailed analysis of body regions, showcasing bone mineral density and body composition metrics.&quot; /&gt;
  &lt;br /&gt;
  &lt;span&gt;Example of commercial software that is used clinically to measure body composition. In this example, we are demonstrating the ability to load and analyze our Pseudo-DXA generated image.&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;generative-ai-in-medical-imaging&quot;&gt;Generative AI in Medical Imaging&lt;/h2&gt;
&lt;p&gt;As previously mentioned, generative AI models for medical imaging are at the forefront of development. Known examples of generative medical models include models for artifact removal from CT images or the production of higher quality CT images from low dose modalities where image quality is known to be lesser in quality. However, prior to our study, generative models creating quantitatively accurate medical images were largely unexplored. Quantitative accuracy is arguably more difficult for generative models to achieve than producing an image of high quality. Anatomical structures not only have to be in the right place, but the pixels representing their location needs to be near perfect as well. When considering the difficulty of achieving quantitative accuracy one must also consider the bit depth of raw medical images. The raw formats of some medical imaging modalities, DXA included, encode information in 12 or 14 bit which is magnitudes more than standard 8-bit images. High bit depths equate to a bigger search space which could equate to it being more difficult to get the exact pixel value. We are able to achieve quantitative accuracy through self-supervised learning methods with a custom physics or DXA informed loss function described in this &lt;a href=&quot;https://arxiv.org/pdf/2206.06663&quot;&gt;work here&lt;/a&gt;. Stay tuned for a deep dive into that work to come in the near future.&lt;/p&gt;

&lt;h2 id=&quot;what-we-did&quot;&gt;What We Did&lt;/h2&gt;
&lt;p&gt;We developed a model that can predict your insides from your outsides. In other words, our model innovatively predicts internal body composition from external body scans, specifically transforming three-dimensional (3D) body surface scans into fully analyzable DXA scans. Utilizing increasingly common 3D body scanning technologies, which employ optical cameras or lasers, our model bypasses the need for ionizing radiation. 3D scanning enables accurate capture of one’s exterior body shape and the technology has several health relevant use cases. Our model outputs a fully analyzable DXA scan which means that existing commercial software can be used to derive body composition or measures of adipose tissue (fat), lean tissue (muscle), and bone. To ensure accurate body composition measurements, our model was designed to achieve both qualitative and quantitative precision, a capability we have successfully demonstrated.&lt;/p&gt;

&lt;h2 id=&quot;inspiration-and-motivation&quot;&gt;Inspiration and Motivation&lt;/h2&gt;
&lt;p&gt;The genesis of this project was motivated by the hypothesis that your body shape or exterior phenotype is determined by the underlying distribution of fat, muscle, and bone. We had previously conducted several studies demonstrating the associations of body shape to measured quantities of muscle, fat, and bone as well as to health outcomes such as metabolic syndrome. Using principal components analysis (PCA), through shape and appearance modeling, and linear regression, a student in our lab showed the ability to predict body composition images from 3D body scans. While this was impressive and further strengthened the notion of the relationship between shape and composition, these predicted images excluded the forelimbs (elbow to hand and knee to feet) and the images were not in a format (raw DXA format) which enabled analysis with clinical software. Our work fully extends and overcomes previous limitations. The Pseudo-DXA model, as we call it, is able to generate the full whole body DXA image from 3D body scan inputs which can be analyzed from using clinical and commercial software.&lt;/p&gt;

&lt;div style=&quot;text-align: center;&quot;&gt;
  &lt;a name=&quot;img-subsection&quot;&gt;&lt;/a&gt;
  &lt;img src=&quot;/assets/images/projects/pseudo_dxa/3d_to_dxa_pca.png&quot; style=&quot;width: 30%;&quot; alt=&quot;Very early proof-of-concept 3D to DXA image translation which sparked this whole project.&quot; /&gt;
  &lt;br /&gt;
  &lt;span&gt;Early proof-of-concept 3D to DXA image translation which sparked this whole project.&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;our-training-data&quot;&gt;Our Training Data&lt;/h2&gt;
&lt;p&gt;The cornerstone of the Pseudo-DXA model’s development was a unique dataset comprising paired 3D body and DXA scans, obtained simultaneously. Such paired datasets are uncommon, due to the logistical and financial challenges in scanning large patient groups with both modalities. We worked with a modest but significant sample size: several hundred paired scans. To overcome the data scarcity issue, we utilized an additional, extensive DXA dataset with over 20,000 scans for model pretraining.&lt;/p&gt;

&lt;h2 id=&quot;building-the-model&quot;&gt;Building the Model&lt;/h2&gt;
&lt;p&gt;The Pseudo-DXA model was built in two steps. The first self-supervised learning (SSL) or pretraining step involved training a variational auto encoder (VAE) to encode and decode or regenerate raw DXA scan. A large DXA data set, which is independent of the data set used in the final model and evaluation of our model, was used to SSL pretrain our model and it was divided to contain an separate hold out test set. Once the VAE model was able to accurately regenerate the original raw DXA image as validated with the holdout test set, we moved to the second phase of training.&lt;/p&gt;

&lt;p&gt;In brief, VAE models consist of two main subnetwork components which include the encoder and the decoder, also known as a generator. The encoder is tasked with taking the high dimensional raw DXA image data and learning a meaningful compressed representation which is encoded into what is known as a latent space. The decoder or generator takes the latent space representation and learns to regenerate the original image from the compressed representation. We used the trained generator from our SSL DXA training as the base of our final Pseudo-DXA model.&lt;/p&gt;

&lt;div style=&quot;text-align: center;&quot;&gt;
  &lt;a name=&quot;img-subsection&quot;&gt;&lt;/a&gt;
  &lt;img src=&quot;/assets/images/projects/pseudo_dxa/semi_supervised_learning_schema.webp&quot; style=&quot;width: 70%;&quot; alt=&quot;Model architecture diagram with the first self-supervised learning phase at the top and the Pseudo-DXA training phase at the bottom.&quot; /&gt;
  &lt;br /&gt;
  &lt;span&gt;Model architecture diagram with the first self-supervised learning phase at the top and the Pseudo-DXA training phase at the bottom.&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;The structure of the 3D body scan data consisted of a series of vertices or points and faces which indicate which points are connected to one another. We used a model architecture resembling the Pointnet++ model which has demonstrated the ability to handle point cloud data well. The Pointnet++ model was then attached to the generator we had previously trained. We then fed the mode the 3D data and it was tasked with learning generate the corresponding DXA scan.&lt;/p&gt;

&lt;h2 id=&quot;pseudo-dxa-results&quot;&gt;Pseudo-DXA Results&lt;/h2&gt;
&lt;p&gt;In alignment with machine learning best practices, we divided our data such that we had an unseen holdout test for which we reported all our results on.&lt;/p&gt;

&lt;h2 id=&quot;image-quality&quot;&gt;Image quality&lt;/h2&gt;
&lt;p&gt;We first evaluated our Pseudo-DXA images using image quality metrics which include normalized mean absolute error (NMAE), peak signal to noise ratio (PSNR), and structural similarity index (SSIM). Our model generated images had mean NMAE, PSNR, and SSIM of 0.15, 38.15, and 0.97, respectively, which is considered to be good with respect to quality. Shown below is an example of a 3D scan, the actual DXA low energy scan, Pseudo-DXA low energy scan and the percent error map of the two DXA scans. As mentioned DXA images have two image channels for high and low energies yet, these examples are just showing the low energy image. Long story short, the Pseudo-DXA model can generate high quality images on par with other medical imaging models with respect to the image quality metrics used.&lt;/p&gt;

&lt;div style=&quot;text-align: center;&quot;&gt;
  &lt;a name=&quot;img-subsection&quot;&gt;&lt;/a&gt;
  &lt;img src=&quot;/assets/images/projects/pseudo_dxa/example_pseudo_dxa_predictions.webp&quot; style=&quot;width: 100%;&quot; alt=&quot;3D scan from the test set, their actual DXA scan, the Pseudo-DXA scan, and error map comparing the actual to the Pseudo-DXA.&quot; /&gt;
  &lt;br /&gt;
  &lt;span&gt;3D scan from the test set, their actual DXA scan, the Pseudo-DXA scan, and error map comparing the actual to the Pseudo-DXA. &lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;quantitative-accuracy&quot;&gt;Quantitative Accuracy&lt;/h2&gt;
&lt;p&gt;When we analyzed our Pseudo-DXA images for composition and compare the quantities to the actual quantities we achieved coefficients of determination (R²) of 0.72, 0.90, 0.74, and 0.99 for fat, lean, bone, and total mass, respectively. An R²of 1 is desired and our values were reasonably close considering the difficulty of the task. A comment we encountered when presenting our preliminary findings at conferences was “wouldn’t it be easier to simply train a model to predict each measured composition value from the 3D scan so the model would for example, output a quantity of fat and bone and etc., rather than a whole image”. The short answer to the question is yes, however, that model would not be as powerful and useful as the Pseudo-DXA model that we are presenting here. Predicting a whole image demonstrates the strong relationship between shape and composition. Additionally, having a whole image allows for secondary analysis without having to retrain a model. We demonstrate the power of this by performing ad-hoc body composition analysis on two user defined leg subregions. If we had trained a model to just output scalar composition values and not an image, we would only be able to analysis these ad-hoc user defined regions by retraining a whole new model for these measures.&lt;/p&gt;

&lt;div style=&quot;text-align: center;&quot;&gt;
  &lt;a name=&quot;img-subsection&quot;&gt;&lt;/a&gt;
  &lt;img src=&quot;/assets/images/projects/pseudo_dxa/ad_hoc_subregion_analysis.png&quot; style=&quot;width: 20%;&quot; alt=&quot;Example of secondary analysis with user defined subregions of the leg labeled R1 and R2.&quot; /&gt;
  &lt;br /&gt;
  &lt;span&gt;Example of secondary analysis with user defined subregions of the leg labeled R1 and R2.&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Long story short, the Pseudo-DXA model produced high quality images that were quantitatively accurate, from which software could measure real amounts of fat, muscle, and bone.&lt;/p&gt;

&lt;h2 id=&quot;so-what-does-this-all-mean&quot;&gt;So What Does This All Mean?&lt;/h2&gt;
&lt;p&gt;The Pseudo-DXA model marks a pivotal step towards a new standard of striving for quantitative accuracy when necessary. The bar for good generative medical imaging models was high image quality yet, as we discussed, good quality may simply not be enough given the task. If the clinical task or outcome requires something to be measured from the image beyond morphology or anthropometry, then quantitative accuracy should be assessed.&lt;/p&gt;

&lt;p&gt;Our Pseudo-DXA model is also a step in the direction of making health assessment more accessible. 3D scanning is now in phones and does not expose individuals to harmful ionizing radiation. In theory, one could get a 3D scan of themselves, run in through our models, and receive a DXA image from which they can obtain quantities of body composition. We acknowledge that our model generates statistically likely images and it is not able to predict pathologies such as tumors, fractures, or implants, which are statistically unlikely in the context of a healthy population from which this model was built. Our model also demonstrated great test-retest precision which means it has the ability to monitor change over time. So, individuals can scan themselves every day without the risk of radiation and the model is robust enough to show changes in composition, if any.&lt;/p&gt;

&lt;p&gt;We invite you to engage with this groundbreaking technology and/or provided an example of a quantitatively accurate generative medical imaging model. Share your thoughts, ask questions, or discuss potential applications in the comments. Your insights are valuable to us as we continue to innovate in the field of medical imaging and AI. Join the conversation and be part of this exciting journey!&lt;/p&gt;

</description>
        <pubDate>Sun, 08 Dec 2024 00:00:00 +0000</pubDate>
        <link>https://www.lambertleong.com/projects/pseudo-dxa-gen-ai</link>
        <guid isPermaLink="true">https://www.lambertleong.com/projects/pseudo-dxa-gen-ai</guid>
        
        <category>ai</category>
        
        <category>machinelearning</category>
        
        <category>healthcare</category>
        
        <category>medicalimaging</category>
        
        <category>generativemodels</category>
        
        
        <category>projects</category>
        
      </item>
    
      <item>
        <title>Optum AI</title>
        <description>&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;

&lt;p&gt;At Optum AI, I work on healthcare machine learning systems that bridge research and production. My role spans model development, evaluation design, stakeholder alignment, and translation of AI capabilities into tools that support healthcare delivery. Much of my recent work has centered on longitudinal healthcare modeling, clinician-facing generative AI, and the evaluation frameworks needed to assess these systems responsibly.&lt;/p&gt;

&lt;div style=&quot;text-align: center;&quot;&gt;
  &lt;img src=&quot;/assets/images/work/Optum-UHG/onsite-team2.jpg&quot; style=&quot;width: 100%;&quot; alt=&quot;Optum AI onsite team photo.&quot; /&gt;
  &lt;br /&gt;
  &lt;span&gt;One of the best parts of the work is partnering closely with the broader team across research, engineering, product, and clinical stakeholders.&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;healthcare-foundation-model-work&quot;&gt;Healthcare Foundation Model Work&lt;/h2&gt;

&lt;p&gt;One of the most meaningful projects I have worked on at Optum AI has been a foundational model for longitudinal care prediction. The underlying idea was to treat a member’s care history as a sequence modeling problem. Instead of words in a sentence, the sequence is composed of healthcare service codes. By retraining an autoregressive Transformer architecture on a custom healthcare vocabulary, we built a model that can learn patterns in how care unfolds over time and use those patterns to predict what services may be relevant next.&lt;/p&gt;

&lt;p&gt;This work became the core engine behind a production recommendation experience. In practice, the model helps surface care-path suggestions that are contextually related to what a member is currently exploring and what similar members have historically used in their plan journey.&lt;/p&gt;

&lt;p&gt;The public Optum / UnitedHealthcare press coverage for this product experience can be found here:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.uhc.com/news-articles/newsroom/consumer-innovation#:~:text=2.%20%E2%80%98Members%20Like%20You%E2%80%99%20%E2%80%93%20AI%2Ddriven%20care%20path%20suggestions%20and%20estimates&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Members Like You: AI-driven care path suggestions and estimates&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;how-it-works-in-product&quot;&gt;How It Works in Product&lt;/h2&gt;

&lt;p&gt;The screenshots below show one example of how the recommendation flow appears in the deployed mobile experience.&lt;/p&gt;

&lt;div style=&quot;text-align: center;&quot;&gt;
  &lt;img src=&quot;/assets/images/work/Optum-UHG/service-search.png&quot; style=&quot;width: 100%;&quot; alt=&quot;Mobile screenshot showing a member searching for a sleep study with personalized search results.&quot; /&gt;
  &lt;br /&gt;
  &lt;span&gt;A member begins by searching for a service. In this example, the search is for a sleep study, and the ranked results include options related to sleep apnea and overnight sleep studies.&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Once the member selects a relevant result such as &lt;strong&gt;Sleep apnea&lt;/strong&gt; or a related sleep study option, they arrive at the cost estimate page. From there, the product can surface a section called &lt;strong&gt;Members also used their plan for&lt;/strong&gt;. That recommendation strip is where my model is serving personalized adjacent suggestions based on learned patterns in longitudinal care sequences.&lt;/p&gt;

&lt;div style=&quot;text-align: center;&quot;&gt;
  &lt;img src=&quot;/assets/images/work/Optum-UHG/service-members-like-you-load.png&quot; style=&quot;width: 100%;&quot; alt=&quot;Mobile screenshot showing the members also used their plan for recommendation section on a sleep study estimate page.&quot; /&gt;
  &lt;br /&gt;
  &lt;span&gt;After the member lands on the service page, the recommendation shelf appears under &lt;strong&gt;Members also used their plan for&lt;/strong&gt;. In this example, the model surfaces related care-path options such as CPAP machine and services and Sleep apnea.&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;If the member taps one of those suggestions, such as &lt;strong&gt;CPAP machine and services&lt;/strong&gt;, they are taken directly to a related cost estimate experience for that downstream service.&lt;/p&gt;

&lt;div style=&quot;text-align: center;&quot;&gt;
  &lt;img src=&quot;/assets/images/work/Optum-UHG/model-output-selected.png&quot; style=&quot;width: 100%;&quot; alt=&quot;Mobile screenshot showing a related CPAP machine and services estimate after selecting a recommendation served by the model.&quot; /&gt;
  &lt;br /&gt;
  &lt;span&gt;This is the downstream recommendation in action: the member selects a related suggestion and moves into another relevant estimate and planning experience.&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;For me, this project is a strong example of what makes health AI exciting: a relatively abstract machine learning idea can be turned into a concrete member-facing feature that improves navigation, supports decision making, and operates within a real healthcare product.&lt;/p&gt;

&lt;h2 id=&quot;other-areas-of-focus&quot;&gt;Other Areas of Focus&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Clinician-facing generative AI:&lt;/strong&gt; I have also contributed to multiple healthcare AI solutions that generate medical-record-grounded text for clinician-in-the-loop workflows, with a focus on usefulness, quality, and safe human oversight.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluation and measurement:&lt;/strong&gt; I built evaluation workflows that combine statistical natural language processing metrics with LLM-based judging strategies to better assess generated outputs in health AI settings.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Responsible AI review:&lt;/strong&gt; I developed tooling to support internal audit and review teams in triaging pre-deployment AI systems against policy, best practices, and historical review patterns.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;what-i-enjoy-most&quot;&gt;What I Enjoy Most&lt;/h2&gt;

&lt;p&gt;One of the most rewarding parts of the work is operating at the boundary between technical depth and real-world constraints. Healthcare AI is not just about building a strong model. It also requires clear communication, careful validation, and close partnership with clinicians, product leaders, and business stakeholders. I enjoy helping different domain experts get aligned on what a system is doing, how it should be evaluated, and what responsible deployment should look like.&lt;/p&gt;
</description>
        <pubDate>Sun, 01 Sep 2024 00:00:00 +0000</pubDate>
        <link>https://www.lambertleong.com/experience/optum-ai</link>
        <guid isPermaLink="true">https://www.lambertleong.com/experience/optum-ai</guid>
        
        <category>health</category>
        
        <category>ai</category>
        
        <category>foundation</category>
        
        <category>models</category>
        
        <category>generative</category>
        
        <category>ai</category>
        
        <category>healthcare</category>
        
        <category>nlp</category>
        
        <category>llm</category>
        
        <category>responsible</category>
        
        <category>ai</category>
        
        <category>machine</category>
        
        <category>learning</category>
        
        
        <category>experience</category>
        
      </item>
    
      <item>
        <title>University of Washington OncoRad Research Core</title>
        <description>&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;

&lt;p&gt;As a Postdoctoral Researcher with the OncoRad Research Core at the University of Washington School of Medicine, I worked on translational imaging and clinical research problems where strong technical methods could directly improve study workflows and biomarker development. The work sat at the intersection of computer vision, natural language processing, imaging analytics, and data engineering.&lt;/p&gt;

&lt;div style=&quot;text-align: center;&quot;&gt;
  &lt;img src=&quot;/assets/images/work/UW-postdoc/UW-imaging-reseach-lab-2024.jpg&quot; style=&quot;width: 100%;&quot; alt=&quot;University of Washington imaging research lab team photo.&quot; /&gt;
  &lt;br /&gt;
  &lt;span&gt;During my postdoc, I worked with a highly collaborative research environment focused on clinically relevant imaging and biomarker problems.&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;research-and-engineering-work&quot;&gt;Research and Engineering Work&lt;/h2&gt;

&lt;p&gt;Some of my work focused on building tools that made clinical imaging research more scalable and more precise:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;I developed an NLP-based case-finding algorithm that achieved 98% accuracy for identifying specific CT imaging sequences in Python.&lt;/li&gt;
  &lt;li&gt;I built a multithreaded deep learning pipeline for body composition measurement from CT images, improving throughput by 8x.&lt;/li&gt;
  &lt;li&gt;I partnered with the Department of Radiology to source, query, and curate research data across School of Medicine databases using SQL to support translational studies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What I liked most about this role was that the technical work had to connect cleanly to real research needs. The goal was not just to build a model, but to make data easier to find, make image processing pipelines practical to run, and help investigators ask better clinical questions with better measurements.&lt;/p&gt;

&lt;h2 id=&quot;computer-vision-and-segmentation-example&quot;&gt;Computer Vision and Segmentation Example&lt;/h2&gt;

&lt;p&gt;One project I contributed to involved segmentation and quantitative measurement workflows for spleen analysis on CT in patients with hematologic malignancies. This kind of work is a good example of the translational nature of the postdoc: computer vision methods were not being developed in isolation, but as part of a measurement pipeline tied to treatment response and clinical trial assessment.&lt;/p&gt;

&lt;div style=&quot;text-align: center;&quot;&gt;
  &lt;img src=&quot;/assets/images/work/UW-postdoc/spleen_segmentation_paper.webp&quot; style=&quot;width: 85%;&quot; alt=&quot;CT segmentation figure showing spleen segmentation and measurement views.&quot; /&gt;
  &lt;br /&gt;
  &lt;span&gt;An example of the segmentation-focused imaging work from my time at UW, where volumetric measurement and image analysis were central to the clinical question.&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Related publication:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Hasenstab KA, Lu J, &lt;strong&gt;Leong LT&lt;/strong&gt;, Bossard E, Pylarinou-Sinclair E, Devi K, Cunha GM. &lt;em&gt;Relationship between spleen volume and diameter for assessment of response to treatment on CT in patients with hematologic malignancies enrolled in clinical trials.&lt;/em&gt; Abdominal Radiology. 2025;50(12):5799-5809. &lt;a href=&quot;https://doi.org/10.1007/s00261-025-05030-7&quot;&gt;DOI: 10.1007/s00261-025-05030-7&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;why-this-role-mattered-to-me&quot;&gt;Why This Role Mattered to Me&lt;/h2&gt;

&lt;p&gt;This postdoctoral experience reinforced something I care about deeply: the best health AI work usually requires more than one skill set at the same time. It is not only model building. It is also study design, data curation, workflow engineering, quantitative validation, and communication with domain experts who care about the underlying clinical meaning. That combination is a big part of what continues to draw me toward applied health AI.&lt;/p&gt;
</description>
        <pubDate>Tue, 01 Aug 2023 00:00:00 +0000</pubDate>
        <link>https://www.lambertleong.com/experience/university-of-washington-postdoc</link>
        <guid isPermaLink="true">https://www.lambertleong.com/experience/university-of-washington-postdoc</guid>
        
        <category>university</category>
        
        <category>of</category>
        
        <category>washington</category>
        
        <category>postdoc</category>
        
        <category>medical</category>
        
        <category>imaging</category>
        
        <category>computer</category>
        
        <category>vision</category>
        
        <category>segmentation</category>
        
        <category>nlp</category>
        
        <category>clinical</category>
        
        <category>research</category>
        
        
        <category>experience</category>
        
      </item>
    
      <item>
        <title>Final DXA-nation</title>
        <description>&lt;p&gt;&lt;strong&gt;LONGITUDINAL IMAGE-BASED AI MODELS FOR HEALTH AND MEDICINE&lt;/strong&gt;
&lt;strong&gt;AI can see the end! Deep learning predicts all-cause mortality from single and sequential body composition imaging.&lt;/strong&gt;&lt;/p&gt;

&lt;h1 id=&quot;key-points-tldr&quot;&gt;Key Points, TLDR:&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;The combination of body composition imaging and meta-data (e.g., age, sex, grip strength, walking speed, etc.) resulted in the best 10-year mortality predictions.&lt;/li&gt;
  &lt;li&gt;Longitudinal or sequential models overall performed better than single record models, highlighting the importance of modeling change and time dependencies in health data.&lt;/li&gt;
  &lt;li&gt;Longitudinal models have the potential to provide a more comprehensive assessment of one’s health.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Artificial intelligence (AI) and machine learning (ML) are revolutionizing
healthcare, driving us toward the era of precision medicine. The motivation to
develop AI health models is to reduce deaths and disease as well as prolong a
high quality of life. Well-trained models have the ability to more thoroughly
analyze data that is presented, offering a more comprehensive assessment of
one’s health.&lt;/p&gt;

&lt;h1 id=&quot;single-record-vs-longitudinal-models&quot;&gt;Single Record vs Longitudinal Models&lt;/h1&gt;

&lt;p&gt;Image-based medical AI/ML models have now reached a maturity where they often
rival or even surpass human performance, adeptly identifying patterns and
anomalies that could easily elude the human eye. However, the majority of these
models still operate on single time-point data, providing an isolated snapshot
of health at one specific instance. Whether these are uni-modal or multi-modal
models, they tend to work with data gathered within a relatively similar
timeframe, forming the foundation of a prediction. Yet, in the broader context
of AI/ML for medical applications, these single time-point models represent
just the first step — the proverbial ‘low hanging fruit.’ One frontier of
medical AI research is longitudinal models which offer a more holistic view of
a person’s health over time.&lt;/p&gt;

&lt;p&gt;Longitudinal models are designed to integrate data from multiple time-points,
capturing an individual’s health trajectory rather than a standalone moment.
These models tap into the dynamic nature of human health, where physiological
changes are constant. The ability to map these changes to specific outcomes or
health questions could be a game-changer in predictive healthcare. The concept
of longitudinal data isn’t new to clinical practice — it’s regularly used to
monitor aging and predict frailty. A prime example is the tracking of bone
mineral density (BMD), a key marker for osteoporosis and frailty. Regular
assessments of BMD can detect significant decreases, indicating potential
health risks.&lt;/p&gt;

&lt;h1 id=&quot;longitudinal-model-development-challenges&quot;&gt;Longitudinal Model Development Challenges&lt;/h1&gt;

&lt;p&gt;Historically, the development of longitudinal models has faced several
significant challenges. Aside from larger data volumes and computation required
per individual, the most critical obstacle lies in the curation of longitudinal
medical data itself. Unlike single time-point data, longitudinal data involves
tracking patients’ health information over prolonged periods, often across
multiple healthcare institutions. This requires meticulous data organization
and management, making the curation process both time-consuming and expensive.
Multiple successful studies have been funded to prospectively collect
longitudinal data. These studies report challenges with respect to patient
retention over a longer observation period. Hence, despite the potential
benefits of longitudinal models, their development has remained a complex,
resource-intensive endeavor.&lt;/p&gt;

&lt;h1 id=&quot;the-goal&quot;&gt;The Goal&lt;/h1&gt;

&lt;p&gt;Changes in body composition, proportions of lean and fat soft tissue and bone,
are known to be associated with mortality. In our study, we aimed to use body
composition information to better predict all-cause mortality, in simpler
terms, the likely timeline of a person’s life. We evaluated the performance of
models built on both single time-point and longitudinal data, respectively
referred to as our ‘single record’ and ‘sequential’ models. Single record
models allowed us to evaluate what type of information was most predictive of
mortality. Development of sequential models were for the purposes of capturing
change over time and evaluating how that affects mortality predictions.&lt;/p&gt;

&lt;h1 id=&quot;the-data&quot;&gt;The Data&lt;/h1&gt;

&lt;p&gt;The data for this study was acquired from a longitudinal known as the Health,
Aging, and Body Composition (Health ABC) study in which over 3000 older,
multi-race male and female adults were followed and monitored for up to 16
years. This study resulted in a rich and comprehensive longitudinal data set.
As a part of this study patients received total body dual energy X-ray
absorptiometry (TBDXA) imaging and several pieces of meta-data were collected.
Consistent with best modeling practices and to avoid data leakage or mitigate
overfitting, the data was split into a train, validation, and hold-out test set
using a 70%/10%/20% split.&lt;/p&gt;

&lt;p&gt;We quantify body composition using total body dual energy X-ray absorptiometry
(TBDXA) imaging which has long been considered a gold standard imaging
modality. Historically, patient meta-data which include variables like age,
body mass index (BMI), grip strength, walking speed, etc were used to assess
aging/mortality and used as surrogate measurement of body composition. The
prevalent use of patient meta-data and surrogate measures of body composition
were driven by the limited accessibility to DXA scanners. Accessibility has
improved greatly as of recent with scans becoming cheaper and no longer needing
a physician referral/order/prescription.&lt;/p&gt;

&lt;h1 id=&quot;single-image-model&quot;&gt;Single Image Model&lt;/h1&gt;

&lt;p&gt;Three single record models were built each with different data inputs but all
with the same output which was a 10 year mortality probability. The first model
was built to only take patient meta-data and is a neural network with a single
32-unit, ReLU activation hidden layer and sigmoid prediction layer. The second
model used only TBDXA images as input and it consisted of a modified
Densenet121 which was modified to handle the two color channels as opposed to
three color channels (RGB) seen in most natural images. The dual energy nature
of DXA results in a high and low X-ray images which are fully registered and
stacked into two image channels. The third model combines the meta-data
embedding of model one with the TBDXA image embeddings of model two then passes
it through a 512-unit, a 64-unit fully-connected ReLU layer to make, and lastly
a sigmoid prediction layer.&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-subsection&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/tbdxa/TBDXA_singlerecord_model_diagram.png&quot; width=&quot;100%&quot; alt=&quot;single record dxa image deep learning model diagram&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 1:&lt;/b&gt;
    Diagram of data inputs, model architectures, and methods for single record models.
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;longitudinalsequential-model&quot;&gt;Longitudinal/Sequential Model&lt;/h1&gt;

&lt;p&gt;Three sequential models were built and evaluated. The single record model
architectures served as the base for each sequential model but the sigmoid
prediction layers were removed so that the output was a vector representing
feature embeddings. Over the course of the study data was collected from each
patient at multiple time points. The data from each time point was input into
the appropriate models to acquire the corresponding feature vector. The feature
vectors for each patient were ordered and stacked into a sequence. A Long Short
Term Memory (LSTM) model was trained to take the sequence of feature vectors
and output a 10 year mortality prediction. As previously mentioned, there are
several difficulties with conducting long term studies with retention and data
collection being a common problem. Our study was not absent of these problems
and some patients had more data points that others as a result. An LSTM model
was chosen as the sequence modeling approach because they are not constrained
to use the same input sequence length for each patient. I.e. LSTMs can work
with sequences of varying length thus eliminating the need to pad sequences if
patients were short the full set of data points (~10).&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-subsection&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/tbdxa/TBDXA_sequence_model_diagram.png&quot; width=&quot;100%&quot; alt=&quot;sequential record dxa image deep learning model diagram&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 2:&lt;/b&gt;
    Diagram of data inputs, model architectures, and methods for sequential models. 
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;image--meta-data-longitudinal-models-win&quot;&gt;Image + Meta-data Longitudinal Models Win&lt;/h1&gt;
&lt;p&gt;Area under the receiver operating characteristic (AUROC) on the hold-out test set show that metadata performs better than using TBDXA image alone in both the single record and sequential models. However, combining meta-data and TBDXA imaging resulted in the best AUROCs in both modeling paradigms which indicates that imaging contains useful information, predictive of mortality that is not captured by the meta-data. Another way to interpret this is that the meta-data are not a full surrogate measure of body composition with respect to predicting mortality. If they were full surrogates, combining TBDXA imaging with meta-data would have resulted in no significant increase or change in AUROC. The fact that the combination resulted in better AUROCs indicates that imaging is providing orthogonal information beyond what the meta-data capture and further justifies the utility of imaging.&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-subsection&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/tbdxa/tb-dxa_auc.jpg&quot; width=&quot;100%&quot; alt=&quot;single and sequential record model AUC performance&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 3:&lt;/b&gt;
    Single Record and Sequential Models AUC Performance. 
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Longitudinal or sequential models overall performed better than single record
models. This is true across all modeling approaches and input data types
(meta-data, image only, combined meta-data and image). These results
demonstrate the importance of modeling change and the time dependencies of
health data.&lt;/p&gt;

&lt;p&gt;We performed an Integrated Discrimination Improvement (IDI) analysis to
evaluate the benefits of combining imaging with metadata, compared to using
metadata alone. This analysis was conducted on the sequence models, which
outperformed the single-record models. The IDI was found to be 5.79, with an
integrated sensitivity and specificity of 3.46 and 2.33, respectively. This
indicates that the combination of imaging and metadata improves the model’s
ability to correctly identify those who will not survive the next 10 years by
3.46%, and enhances the ability to correctly identify those who will survive
the next 10 years by 2.33%. Overall, this suggests an improvement in model
performance of approximately 5.8%.&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-subsection&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/tbdxa/TBDXA_IDI.png&quot; width=&quot;100%&quot; alt=&quot;single and sequential record model AUC performance&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 4:&lt;/b&gt;
    Integrated Discrimination Improvement (IDI) analysis results . 
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;so-what&quot;&gt;So What?&lt;/h1&gt;

&lt;p&gt;Our study underscores the promising potential of longitudinal AI/ML models in
the realm of predictive healthcare, specifically in the context of all-cause
mortality. The comparative analysis of single record models and longitudinal
models revealed that the latter offers superior performance, indicating the
critical role of modeling change over time in health data analysis. The
clinical implication of our findings include the ability to provide a more
precise and holistic assessment of one’s health through models that account for
a patient’s historical or longitudinal data. In addition, our in-depth analysis
towards explainable AI provided insights into which variables are closely
related to high 10-year mortality probability. Some of these variables are
modifiable and can be addressed clinically, offering many the opportunity to
improve their longevity and healthspan. While the data needed for developing
longitudinal health models exists, the proper infrastructure and institutional
support is not quite oriented yet to enable efficient data curation and
development of these models at scale. Nevertheless, many are working to
overcome these hurdles and the development of longitudinal models is one of
many exciting frontiers for AI in medicine.&lt;/p&gt;

&lt;p&gt;The clinical implications of these findings are far-reaching. Longitudinal
models have the potential to transform care delivery by enabling more precise,
personalized predictions about a patient’s health trajectory. Such models can
inform proactive interventions, thereby enhancing care outcomes and possibly
even prolonging life. Moreover, the use of both metadata and imaging data sets
a new precedent for future AI/ML models, suggesting a synergistic approach for
optimal results. It reinforces the need for multidimensional, nuanced data to
paint an accurate and holistic picture of a patient’s health. These findings
represent significant strides in the application of AI/ML in healthcare,
highlighting an exciting path forward in our pursuit of precision medicine.&lt;/p&gt;

&lt;h1 id=&quot;more-resources&quot;&gt;More Resources:&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.nature.com/articles/s43856-022-00166-9&quot;&gt;Read the paper on Nature&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;towardsdatascience.com&quot;&gt;More Information about IDI and published examples on Towards Data Science&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;github.com/LambertLeong/AUC_NRI_IDI_python_functions&quot;&gt;GitHub - LambertLeong/AUC_NRI_IDI_python_functions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;www.lambertleong.com&quot;&gt;Area Under the Curve and Beyond with Integrated Discrimination Improvement and Net Reclassification&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Sat, 22 Jul 2023 00:00:00 +0000</pubDate>
        <link>https://www.lambertleong.com/projects/final-dxa-nation</link>
        <guid isPermaLink="true">https://www.lambertleong.com/projects/final-dxa-nation</guid>
        
        <category>ai</category>
        
        <category>machinelearning</category>
        
        <category>aging</category>
        
        <category>healthcare</category>
        
        <category>imageprocessing</category>
        
        <category>datascience</category>
        
        <category>longitudinal</category>
        
        
        <category>projects</category>
        
      </item>
    
      <item>
        <title>Photo Mosaics with Nearest Neighbors: Machine Learning for Digital Art</title>
        <description>&lt;h1 id=&quot;tldr&quot;&gt;TLDR&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;Machine learning can be used artistically to create photo mosaics&lt;/li&gt;
  &lt;li&gt;Modeling with K-nearest neighbors offers a robust method for searching when exact matches are not always possible.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=tq-sQ0m1R40&amp;amp;list=PLvaAMsy5gV_UMmFxdwHYm00U6OrG-JLvp&quot;&gt;Checkout the whole catalog of photo mosaic animations&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;what-is-a-photo-mosaic&quot;&gt;What is a Photo Mosaic&lt;/h1&gt;

&lt;p&gt;Here’s an example!&lt;/p&gt;
&lt;center&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/kzmm4PKCWW4&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
 &lt;br /&gt;
    Zoom in animation, Recommend watching in full screen
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;
Technological innovation is increasing at a rapid pace and has made digital
storage extremely cheap and accessible. Additionally, most people now have
phones with cameras that are able to capture high quality images. The majority
of images taken are viewed a few times and then sent to sit on a hard drive or
some cloud storage service. This results in people amassing large libraries of
pictures. I am no different and since I had some extra time during the COVID-19
lockdowns, I came up with some software to give the photos in people’s
libraries a second life. This software creates photo mosaics.&lt;/p&gt;

&lt;p&gt;A photo mosaic is an image or photo that is created by stitching together many
smaller images. In the gif and videos above, it is easy to see how many small
image squares are used to create a larger picture. There are several methods
for creating these mosaics; for instance, the smaller image squares or tiles
can be chosen and placed in the larger image based on color or image structure.
In this post, we focus on a color matching strategy and it is of particular
interest to a data science or machine learning audience because it utilizes
K-nearest neighbors (KNN) modeling approach.&lt;/p&gt;

&lt;h1 id=&quot;framing-the-problem&quot;&gt;Framing the Problem&lt;/h1&gt;

&lt;p&gt;As always, it is good practice to deconstruct the problem and build functions
around the various components that are needed to accomplish the goal. First we
need to divide the larger or cover image into smaller subsections (see &lt;a href=&quot;#img-subsection&quot;&gt;Figure 1. below&lt;/a&gt;). Once we have
the smaller subsections then we can find the image tile that would match each
subsection. We are using a color matching method to build the mosaic and thus
we can formalize the problem as follows: for every cover image subsection, find
a tile image that most closely matches the color.&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-subsection&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/photo_mosaic/gumwall_grid.png&quot; width=&quot;50%&quot; alt=&quot;Cover Photo Sub Sections&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 1:&lt;/b&gt;
    Here we divide our cover image up into square subsections denoted by the white line.
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;structure-of-color-images&quot;&gt;Structure of Color Images&lt;/h1&gt;

&lt;p&gt;Digital color images are composed of different pixel color channels that when
combined create a colored image. A common format is red green blue or RGB image
formats in which a colored image is made up of red, green, and blue channels.
Images are commonly stored in 8-bits which means that pixel values for each of
the color channels range between 0 and 255 (2^8-1).&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-color_matching&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/photo_mosaic/image_channels_match.png&quot; width=&quot;80%&quot; alt=&quot;Cover Photo Sub Sections&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 2:&lt;/b&gt;
    Here we capture the average RGB values for both the subsection (top) and the tile (bottom).
    There is not exact match for this subsection in the library but it is close.
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;If we take the average red, green, and blue pixel value for each image we can
use three numbers to describe the general color in each image. Therefore, to
find the tile that fits in each subsection we need to find the tile with the
same average RGB pixel values. We can first start by creating a list of average
RGB pixel values for each subsection in the cover image. We can then make a
list of average RGB pixel values from our library of tile photos. Once the two
list are created we can iterate over the subsection list and search the library
of tiles list to find matching average RGB pixel values. Using clever dynamic
programming and efficient data structures this search can be performed
relatively fast. There is a major flaw with this approach that needs to be
addressed however. It may be the case that your library of tile images is
incomplete and not every average RGB pixel value is represented. Therefore, a
search for the tile with the exact average RGB value will result in nothing, &lt;a href=&quot;#img-color_matching&quot;&gt;see Figure 2&lt;/a&gt;.
The solution would be to find the next tile with the closest matching average
RGB value. Extensive research has gone into determining “closeness” with
respect to colors. For example, it is well understood that the colors black and
white are not close at all. Our solution, however, is a simple one and it
utilizes machine learning.&lt;/p&gt;

&lt;h1 id=&quot;closest-color-with-k-nearest-neighbors&quot;&gt;Closest Color with K-Nearest Neighbors&lt;/h1&gt;

&lt;p&gt;Each subsection and tile are represented by three numbers for the average red,
green, and blue colors values. We can think of the three color values as a
separate dimension and thus, we can create a 3D plot where each color is a
dimension or axis. If we plot the values of the subsection, for which we are
looking for a matching tile, with possible tiles in our library we can see
which tiles have the closest color values.&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-knn&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/photo_mosaic/knn_color_search.gif&quot; width=&quot;80%&quot; alt=&quot;Cover Photo Sub Sections&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 3:&lt;/b&gt;
    The average RGB value for the subsection is plotted in red. Tiles with close RGB values are plotted in orange.
    Using KNN we can find the nearest match shown with the yellow &quot;X&quot;.
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;The KNN algorithm can evaluate all tiles in the library and model the average
pixel value. Then when searching for matching tiles for each subsection, the
model will return the closest neighbor or tile with the color values that match
most closely. &lt;a href=&quot;#img-knn&quot;&gt;This search is illustrated in Figure 3.&lt;/a&gt; Using KNN is more robust than doing a brute force search for the
exact value since there are instances where the exact value may not exist.
Under the hood, KNN models can be built using a tree-like structure which makes
searching or traversing it relatively efficient. As such, performance is also
comparable to other solutions that we have mentioned. Once all the tiles are
found for each subsection color, simple array/matrix indexing can be used to
stitch together all the tile images to create the final mosaic of the cover
photo.&lt;/p&gt;

&lt;h1 id=&quot;closing&quot;&gt;Closing&lt;/h1&gt;

&lt;p&gt;&lt;a href=&quot;lamberttleong@gmail.com&quot;&gt;If you would like your own photo mosaic or need help building your one, please feel free to reach out.&lt;/a&gt;
We can repurpose your old images that are collecting dust on some hard drive somewhere and give them a second chance at something beautiful.neighbors.
Hey maybe they can even become NFTs!&lt;/p&gt;

&lt;p&gt;Let’s look at another example photo mosaic with a different animation. All animations
are made programmatically and will be detailed in following post.&lt;/p&gt;

&lt;center&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/tq-sQ0m1R40&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
 &lt;br /&gt;
    Disperse animation, Recommend watching in full screen
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Code available upon reasonable request.&lt;/p&gt;
</description>
        <pubDate>Sun, 03 Jul 2022 00:00:00 +0000</pubDate>
        <link>https://www.lambertleong.com/projects/photo-mosaic</link>
        <guid isPermaLink="true">https://www.lambertleong.com/projects/photo-mosaic</guid>
        
        <category>photograhy</category>
        
        <category>imageprocessing</category>
        
        <category>image</category>
        
        <category>processing</category>
        
        <category>mosaic</category>
        
        <category>software</category>
        
        <category>datascience</category>
        
        <category>data</category>
        
        <category>science</category>
        
        <category>photomosaic</category>
        
        <category>knn</category>
        
        <category>machine</category>
        
        <category>learning</category>
        
        
        <category>projects</category>
        
      </item>
    
      <item>
        <title>Artificial Intelligence Can See Breast Cancer Before it Happens</title>
        <description>&lt;h1 id=&quot;key-points&quot;&gt;Key Points&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;Our image base deep learning model identified &lt;strong&gt;unique&lt;/strong&gt; signals of screen-detected cancer risk&lt;/li&gt;
  &lt;li&gt;Breast density is a better predictor of interval cancer risk&lt;/li&gt;
  &lt;li&gt;This post is in direct response to the article entitled, &lt;a href=&quot;https://pubs.rsna.org/doi/abs/10.1148/radiol.2021203758&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;“Deep Learning Predicts Interval and Screening-detected 
Cancer from Screening Mammograms: A Case-Case-Control Study in 6369 Women”&lt;/strong&gt;&lt;/a&gt;,
published in Radiology and presented at the &lt;a href=&quot;https://press.rsna.org/timssnet/media/pressreleases/14_pr_target.cfm?ID=2280&quot; target=&quot;_blank&quot;&gt;Radiological Society of North America (RSNA)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;contents&quot;&gt;Contents&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#head-why-risk&quot;&gt;Why is Risk Important&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-solution&quot;&gt;Current Risk Solutions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-ai-modeling&quot;&gt;Our Contribution Towards the Risk Solution&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-results&quot;&gt;Surprising Results&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-next&quot;&gt;What’s Next&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The use of artificial intelligence (AI) and deep learning (DL) in the medical and healthcare field has been increasing 
at an astonishing rate. While the Health Insurance Portability and Accountability Act (HIPAA) is important for the 
protection of personal health information, it presented as the biggest barrier for gathering large data sets required 
for deep learning. Several strategies have been successfully implemented to gather lots of data for training medical AI 
systems without risking patient privacy. AI continues to have a significant impact on medical imaging and deep learning 
models are constantly being developed to look for anomalies such as bone fractures or possible cancer.&lt;/p&gt;

&lt;p&gt;The introduction of breast cancer screening has helped to reduce cancer mortality rates in women as well as provide a 
consistent source of image data. Typically, women 40 years and older receive biannual or annual screening mammograms to 
check for any signs of cancer. Many have developed AI to detect and segment cancers within a mammogram yet, fewer have
developed image based deep learning models to predict risk. In the work being described, we developed a model to predict
an individual’s breast cancer risk; more specifically interval and screen-detected cancer risk.&lt;/p&gt;

&lt;h2 id=&quot;why-is-risk-important-&quot;&gt;Why is Risk Important? &lt;a name=&quot;head-why-risk&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;center&gt;
  &lt;a name=&quot;img-stock&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/deep_learning_breast_cancer_risk/breast_cancer_risk.jpg&quot; width=&quot;85%&quot; alt=&quot;artificial intelligence breast cancer&quot; /&gt;
&lt;br /&gt;
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Predicting breast cancer risk is analogous to forecasting which is an innately hard problem in all fields of science. 
By comparison, accurately quantifying a patient’s risk of cancer is more difficult than detecting the presence of cancer
through some diagnostic test like a mammogram. Understanding breast cancer risk and the many factors associated with it
is important for cancer prevention and monitoring strategies. The best way to reduce cancer mortality is to prevent 
cancer from developing in the first place and accurate assessments of risk are essential.&lt;/p&gt;

&lt;p&gt;There are three clinically relevant outcomes when evaluating risk within a screening population.  These outcomes include
screen-detected (case), interval (case), or no (control) cancer risk. A screen-detected cancer is a cancer that is found
as a result of a routine screening mammogram. In our study, we further defined it as a cancer that occurred within 12 
months after a positive screening mammogram. An interval cancer is a cancer that is found between the normal screening 
interval (biannual or annual) and was defined in our study as an invasive cancer that occurred within 12 months after 
a negative screening mammogram. Interval cancers are known to grow more rapidly and be more aggressive in biology. They 
are often found through palpation or self examination.&lt;/p&gt;

&lt;h2 id=&quot;current-risk-solutions-&quot;&gt;Current Risk Solutions &lt;a name=&quot;head-solution&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;The Gail, BRCAPRO, Tyrer-Cuzick, and Breast Cancer Surveillance Consortium (BCSC) risk models are examples of 
established models used clinically. They all use varying combinations of known breast cancer risk factors which can 
include age, body mass index (BMI), and/or breast density. Imaging is not directly used in clinical models and 
oftentimes only used to get better measurements of breast density. A few image based AI models have been published 
demonstrating comparable risk predictions performance. However, these AI models were constrained to a binary 
classification and did not include the three possible outcomes within a screening population.&lt;/p&gt;

&lt;h2 id=&quot;our-contribution-towards-the-risk-solution-&quot;&gt;Our Contribution Towards the Risk Solution &lt;a name=&quot;head-ai-modeling&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;Our dataset consisted of 6,369 women recruited from the Mayo Clinic and the University of California at San Francisco.
Four standard mammographic views which include the craniocaudal (CC) and mediolateral oblique (MLO) views for both the
left and right breast were acquired on each woman. Mammographic images were received in their raw or “for-processing” 
format with pixel ranges between 0 and 2&lt;sup&gt;14&lt;/sup&gt;. Custom built software was used to filter the image into the 
“for-presentation” format that radiologists are used to reading. It is important to reiterate that the images used for 
our risk modeling were acquired at least 6 months prior to cancer diagnosis. Thus the images we use for modeling were 
negative and contained no visible cancers as determined by expert radiologists.&lt;/p&gt;

&lt;p&gt;Model development took place at the University of Hawaii Cancer Center. A self imposed blind was implemented to account 
for possible overfitting. The data was split into a train and hold-out test set and the test set was never sent to the 
University of Hawaii. We further split the training set into a train, validate, and test set for our initial model 
development. Once we were confident in our modeling architecture and hyperparameters were optimized, the final model was
trained on the entire training set.  The final risk model was then sent to our collaborates to be evaluated on the
hold-out test set. The process was very &lt;a href=&quot;https://www.kaggle.com/competitions&quot; target=&quot;_blank&quot;&gt;kaggle-esque&lt;/a&gt;.&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-model&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/deep_learning_breast_cancer_risk/deeplearning_netowrk.png&quot; width=&quot;80%&quot; alt=&quot;Deep Learning Architecture&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 1:&lt;/b&gt; Four parallel networks for each mammographic view
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;The novelty of our deep learning model resulted from using four parallel networks to look at all imaging information 
simultaneously for prediction, seen in &lt;a href=&quot;#img-model&quot;&gt;Figure 1&lt;/a&gt;. Other than density, imaging biomarkers of risk are underexplored and not well 
characterized. Although cancer may develop in only one side of the breast, we suspected signals of risk may be present 
throughout both the ipsilateral and contralateral breast. Each of the four networks was responsible for learning the 
information in one of the four mammographic views and so there was a LCC, RCC, LMLO, and RMLO network. Outputs from all 
networks were pooled and used to make final predictions of risk.&lt;/p&gt;

&lt;h2 id=&quot;surprising-results-&quot;&gt;Surprising Results! &lt;a name=&quot;head-results&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;Using an objective versus else approach, we evaluated risk predictions using area under the receiver operating 
characteristic curve (AUC). Our model performed with an AUC of 0.66 when classifying controls verse everything else, 
0.63 when classifying screen-detected cancer verse everything else, and 0.71 when classifying interval cancer verse 
everything else. See &lt;a href=&quot;#img-auc&quot;&gt;Figure 2&lt;/a&gt;. Risk modeling is a hard problem and these results are on par, if not better, than current clinical 
risk models.&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-auc&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/deep_learning_breast_cancer_risk/ccc_auc.png&quot; width=&quot;90%&quot; alt=&quot;Deep learning risk prediction AUC performance&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 2:&lt;/b&gt; Final model performance on hold-out test set measured by area under the receiver operating characteristic curve (AUC) 
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;To further interrogate possible imaging signals of risk, we compared our AI models performance against conditional 
logistic regression models built using common clinical risk factors.  These risk factors included clinical and automated
Breast Imaging Reporting and Data System (BI-RADS), BMI, and dense volume.  Automated measurements were obtained using 
Volpara which is a clinically approved breast density software.  In the screen-detected cancer case, c-statistics 
improved when combining risk factors with deep learning, shown in &lt;a href=&quot;#img-risk-factor&quot;&gt;Figure 3&lt;/a&gt;. This improvement indicated that deep learning was able to pick 
up on &lt;u&gt;imaging signals related to risk that are orthogonal or unique to clinical risk factors&lt;/u&gt;. Although we 
hypothesized it, it was still surprising! In the interval cancer case, deep learning models were not able to outperform
models built on breast density alone. In other words, &lt;u&gt;breast density remains the most powerful predictor of interval
cancer risk&lt;/u&gt;. This was even more surprising!! Breast density is a risk factor because dense tissue can obscure images
and mask possible lesions. Dense tissue may also be masking possible signals of risk and impairing our AI models performance.&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-risk-factor&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/deep_learning_breast_cancer_risk/deep_learning_performance.png&quot; width=&quot;100%&quot; alt=&quot;Deep learning vs clinical risk factors&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 3:&lt;/b&gt; Deep learning performance compared against clinical risk factor models
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;whats-next-&quot;&gt;What’s Next &lt;a name=&quot;head-next&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;Disentangling the density signal away from possible interval cancer risk signals is a possible future direction of this 
research. There are more advanced AI techniques, such as adversarial approaches, that may be helpful for understanding 
the interplay between breast density, imaging, and interval cancer risk. Hawaii has a higher incidence of late stage 
cancer when compared to the rest of the United States. The mechanism is not yet known but many hypothesize that the 
unique ethnic makeup of the population plays a role. Our success with deep learning in this study gives us confidence 
that predicting risk of late stage cancer is possible. We welcome comments, conversations, discussion, and collaboration 
on topics discussed here. Feel free to reach out and join the fight against cancer.&lt;/p&gt;

&lt;h3 id=&quot;continuing-the-discussion&quot;&gt;Continuing the Discussion&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://pubs.rsna.org/doi/abs/10.1148/radiol.2021203758&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Read the paper&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/shepherd-lab/dl-mammography&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Check out the github&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.lambertleong.com/contact&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Contact an author&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://shepherdresearchlab.org/about/our-team/&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Contact the lab&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Sat, 05 Feb 2022 00:00:00 +0000</pubDate>
        <link>https://www.lambertleong.com/projects/deep-learning-breast-cancer-risk</link>
        <guid isPermaLink="true">https://www.lambertleong.com/projects/deep-learning-breast-cancer-risk</guid>
        
        <category>breast</category>
        
        <category>cancer</category>
        
        <category>X-ray</category>
        
        <category>mammography</category>
        
        <category>radiology</category>
        
        <category>machine</category>
        
        <category>learning</category>
        
        <category>AI</category>
        
        <category>artificial</category>
        
        <category>intelligence</category>
        
        <category>deep</category>
        
        <category>learning</category>
        
        <category>risk</category>
        
        
        <category>projects</category>
        
      </item>
    
      <item>
        <title>Compositional Imaging with Artificial Intelligence to Improve Breast Cancer Detection</title>
        <description>&lt;h1 id=&quot;tldr&quot;&gt;TLDR&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;This post is in direct response to the article entitled, &lt;a href=&quot;https://www.nature.com/articles/s43856-021-00024-0&quot; target=&quot;_blank&quot;&gt;“Dual-energy three-compartment breast imaging for compositional
biomarkers to improve detection of malignant lesions”&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Compositional breast imaging allows for the discovery of novel biomarkers of cancer&lt;/li&gt;
  &lt;li&gt;Compositional information is diagnostically relevant and could help improve cancer detection thus reducing the number of 
unneeded biopsies.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;contents&quot;&gt;Contents&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#head-breast-imaging&quot;&gt;Current Breast Cancer Imaging Technologies&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-biopsy&quot;&gt;The Biopsy Problem&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-compositional-imaging&quot;&gt;What is Compositional Imaging&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-composition&quot;&gt;How Can Composition Help&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-ai&quot;&gt;The Role of Artificial Intelligence &lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-next&quot;&gt;What is Next for 3CB&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;current-breast-cancer-imaging-technologies-&quot;&gt;Current Breast Cancer Imaging Technologies &lt;a name=&quot;head-breast-imaging&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;As of today (2021) breast cancer is the leading cause of cancer mortality in women, worldwide. There are several 
treatment options such as surgical removal, chemotherapy, and radiation however, it is only a part of the solution. 
Finding and identifying cancers early is just as important, if not more, than the treatments themselves.&lt;/p&gt;

&lt;p&gt;Imaging has had a tremendous impact on reducing cancer mortality. Mammography, an X-ray based imaging technique, is the
primary imaging technology for breast cancer and it allows clinicians to see the underlying tissues and structures.
Within the last decade, digital breast tomosynthesis (DBT) has become the standard of care and this imaging technique 
results in a three dimensional (3D) X-ray image while standard mammography provides a 2D image.&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-CAD&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/nature_commsmed_3cb_icad/CAD_delineations.png&quot; width=&quot;50%&quot; alt=&quot;computer-aided detection (CAD) delineates invasive brest cancer&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 1:&lt;/b&gt; Computer-aided Detection (CAD) finds masses (green), calcifications (red), and calcifications clusters (blue).
    The actual cancerous lesion found by the radiologist is in yellow.
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Images acquired from standard mammography or DBT are reviewed by radiologists who look for suspicious lesions and 
calcifications. Calcifications in breast tissue are not uncommon and sometimes indicate cancer or a risk of developing
cancer.  &lt;a href=&quot;#img-CAD&quot;&gt;Computer-aided detection or CAD software&lt;/a&gt; has been developed and approved by the food and drug administration 
(FDA) to help assist clinicians with the process of screening images for cancer.  Recent advances in artificial 
intelligence (AI) has led to drastic improvements in CAD and even the development of AI based CAD software.&lt;/p&gt;

&lt;h2 id=&quot;the-biopsy-problem-&quot;&gt;The Biopsy Problem &lt;a name=&quot;head-biopsy&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;So with all these great advances in breast imaging technology the fight against cancer should be easier right? The
simple answer is yes but there is a slight problem. While it is true that imaging has helped to identify more cancers 
and reduce mortality rates, there is still the issue of false positive biopsies. When a lesion is deemed suspicious on
imaging, it is biopsied. A biopsy is an invasive procedure in which a tissue sample of the suspicious lesion is taken 
from a woman’s breast to be viewed under a microscope. A false positive biopsy means that the pathologist did not find 
any signs of cancer in the tissue and the lesion seen on imaging is benign or non-cancerous. Essentially, false 
positives lead to unnecessary invasive biopsies and can be detrimental to a person’s physical and mental health. 
This problem exists in part because imaging has become more sensitive and many more lesions can be seen. However, 
specificity has not improved enough meaning it is still difficult to tell a cancerous lesion from a non-cancerous lesion.&lt;/p&gt;

&lt;h2 id=&quot;what-is-compositional-imaging-&quot;&gt;What is Compositional Imaging &lt;a name=&quot;head-compositional-imaging&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;T&lt;a href=&quot;#img-3cb&quot;&gt;hree compartment breast (3CB) imaging&lt;/a&gt; is a dual-energy X-ray technique that produces images or maps of the different 
tissue types within an imaged breast. The 3CB technique was inspired by dual-energy X-ray absorptiometry (DXA) which is
commonly used to evaluate bone density and body composition. With 3CB, two images are taken in quick succession. One
image is at a low energy, equivalent to a standard mammogram, and the other image is taken at a higher energy. X-rays 
at different energies will have different behaviors when passing through different tissues and the contrasts between the
high and low energy X-ray images are used to derive the specific tissue types. The 3CB imaging technique helps to 
visualize and quantify the amount of lipid, water, and protein in the breast.&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-3cb&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/nature_commsmed_3cb_icad/invasive_breast_cancer_3cb.png&quot; width=&quot;90%&quot; alt=&quot;three compartment breast (3cb)_&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 2:&lt;/b&gt; Standard mammogram next to its lipid, water, and protein maps derived from dual-energy three compartment breast 
    (3CB) compositional imaging. 
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;It should be noted that higher energy X-rays used in 3CB are safe and the level of radiation is nothing to be concerned 
with. In fact, 3CB imaging requires only 2 images while standard DBT images require about 7 to 9 images, depending on 
the system. Therefore, the level of additional radiation resulting from the 3CB technique is comparable, if not lower, 
than a DBT image sequence. To further insist on the safety of 3CB, contrast enhanced mammography (CEM) uses a nearly 
identical imaging protocol in which high and low energy images are acquired. CEM is also approved by the FDA and may be
overall more risky than 3CB since the contrast agent used in CEM could provoke a bad reaction in anaphylaxis.&lt;/p&gt;

&lt;h2 id=&quot;how-can-composition-help-&quot;&gt;How Can Composition Help &lt;a name=&quot;head-composition&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;It has been known that composition is important with respect to breast cancer.  Breast density is a powerful risk factor
and density often results from high fibroglandular tissue or protein. Others have studied breast cancer lesions at a
cellular/molecular level and discovered that invasive lesion types tend to consume or metabolize lipids. It is 
hypothesized that the mechanism for this behavior was due to the aggressive growth nature of invasive breast lesions. 
Lipids or fats are an energy source and aggressive tumors will consume whatever they can to fuel their rapid growth.&lt;br /&gt;
As a result, we found that we could pick up on a signal that characterized malignant lesion types. This &lt;a href=&quot;#img-comp-sig&quot;&gt;signal&lt;/a&gt; consisted
of cancerous lesions having lower fat or lipid content when compared to the surrounding regions.&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-comp_sigs&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/nature_commsmed_3cb_icad/lesion_compositional_signatures.png&quot; width=&quot;90%&quot; alt=&quot;breast lesion compositional signatures&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 3:&lt;/b&gt;  The lipid, water, and protein signatures were captured at 2, 4, and 6 millimeters from the lesion. 
    The space between the orange and blue dashed lines show a significant difference in composition for cancerous and non-cancerous 
    lesion types.  
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;the-role-of-artificial-intelligence--&quot;&gt;The Role of Artificial Intelligence  &lt;a name=&quot;head-ai&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;To demonstrate the utility of our 3CB compositional imaging we used AI to see if the compositional difference between 
cancerous and non-cancerous lesions could be learned.  We also wanted to see how the compositional information derived 
from the 3CB technique adds useful diagnostic information to existing clinical paradigms.  We used CAD as our baseline 
and we wanted to see if AI with 3CB could outperform CAD.&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-auc&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/nature_commsmed_3cb_icad/cad_vs_deeplearnin_auroc.png&quot; width=&quot;90%&quot; alt=&quot;3CB adds diagnostic information to improve CAD detection of breast cancer&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 4:&lt;/b&gt; Area under the receiver operating characteristic curves (AUC) for CAD and CAD+3CB performance with 
    95% confidence intervals (CI). The orange line indicates better detection performance for CAD with composition versus CAD
    alone, shown in blue.
    &lt;br /&gt;
    &lt;i&gt;*Code used to generate AUC with CI plot detailed &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://lambertleong.medium.com/area-under-the-curve-and-beyond-f87a8ec6937b&quot;&gt;HERE&lt;/a&gt;
     or &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://www.lambertleong.com/thoughts/auc-idi-nri&quot;&gt;HERE&lt;/a&gt;&lt;/i&gt;
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;As you can see from our &lt;a href=&quot;#img-auc&quot;&gt;area under the receiver operating characteristic curves (AUC)&lt;/a&gt; that the AI+3CB+CAD model 
outperformed CAD alone. This indicates that composition is important and offers additional information not captured 
solely by CAD. In other words, CAD and radiologists with standard mammography use shape, texture, and morphometry 
information for identifying cancer. 3CB offers that same information as well as composition which has proven to be 
beneficial.  The integrated discrimination improvement (IDI) plot shows that the improved performance is manly due to a
reduction in false positives.  As discussed before, there is a biopsy problem and reducing false positives using 3CB 
composition could reduce unnecessary biopsies and ameliorate the problem.&lt;/p&gt;

&lt;center&gt;
  &lt;a name=&quot;img-IDI&quot;&gt;&lt;/a&gt;
&lt;img src=&quot;/assets/images/projects/nature_commsmed_3cb_icad/idi_nri_birads_curve.png&quot; width=&quot;90%&quot; alt=&quot;3CB improves performance by increasing specificity&quot; /&gt;
&lt;br /&gt;
    &lt;b&gt;Figure 5:&lt;/b&gt; Integrated discrimination improvement (IDI) and net reclassification index (NRI) showing that 3CB
    improves specificity. Metrics are plotted next to Breast Imaging-Reporting and Data System (BI-RADS) cutoffs for clinical reference. 
        &lt;br /&gt;
        &lt;i&gt;*Code used to generate IDI with NRI plots detailed &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://lambertleong.medium.com/area-under-the-curve-and-beyond-f87a8ec6937b&quot;&gt;HERE&lt;/a&gt;
         or &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href=&quot;https://www.lambertleong.com/thoughts/auc-idi-nri&quot;&gt;HERE&lt;/a&gt;&lt;/i&gt;
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;what-is-next-for-3cb-&quot;&gt;What is Next for 3CB &lt;a name=&quot;head-next&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;We are continuing our work and research on 3CB by adapting the protocol to work with CEM machines 
&lt;a href=&quot;https://reporter.nih.gov/project-details/10316696&quot; target=&quot;_blank&quot;&gt;1R01CA257652-01A1&lt;/a&gt;.
Using existing contrast enhanced mammography machines approved by FDA for our 3CB imaging would help accelerate the 
adoption of the technology.&lt;/p&gt;

&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;

&lt;p&gt;&lt;a name=&quot;ref-leong&quot; href=&quot;https://www.nature.com/articles/s43856-021-00024-0&quot; target=&quot;_blank&quot;&gt;[1]&lt;/a&gt; Leong, L., Malkov, S., Drukker, K., Niell, B., Sadowski, P., Wolfgruber, T., … &amp;amp; Shepherd, J., Dual-energy three
  compartment breast imaging (3CB) for novel compositional biomarkers to improve detection of malignant lesions, (2021).&lt;/p&gt;

</description>
        <pubDate>Sun, 14 Nov 2021 00:00:00 +0000</pubDate>
        <link>https://www.lambertleong.com/projects/compositional-breast-cancer-ai</link>
        <guid isPermaLink="true">https://www.lambertleong.com/projects/compositional-breast-cancer-ai</guid>
        
        <category>breast</category>
        
        <category>cancer</category>
        
        <category>X-ray</category>
        
        <category>mammography</category>
        
        <category>radiology</category>
        
        <category>CAD</category>
        
        <category>machine</category>
        
        <category>learning</category>
        
        <category>AI</category>
        
        <category>artificial</category>
        
        <category>intelligence</category>
        
        <category>deep</category>
        
        <category>learning</category>
        
        
        <category>projects</category>
        
      </item>
    
      <item>
        <title>Area Under the Curve and Beyond with Integrated Discrimination Improvement and Net Reclassification</title>
        <description>&lt;h2 id=&quot;contents&quot;&gt;Contents&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#head-auc&quot;&gt;AUC&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-bc&quot;&gt;Breast Cacner Example&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-issue&quot;&gt;Issues with AUC&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-beyond&quot;&gt;Beyond the Curve&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-nri&quot;&gt;NRI&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-idi&quot;&gt;IDI&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#head-final&quot;&gt;Final Thoughts&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tldr&quot;&gt;TLDR&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;AUC&lt;/strong&gt; is a good starting metric when comparing the performance of two models but it does not always tell the whole story&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;NRI&lt;/strong&gt; looks at the new models ability to correctly reclassify event and nonevents and should be used alongside AUC&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;IDI&lt;/strong&gt; quantifies improvement of the slopes of the discrimination curves and plotting it can provide information AUC alone does not afford.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://doi.org/10.5281/zenodo.4741253&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;https://zenodo.org/badge/DOI/10.5281/zenodo.4741253.svg&quot; alt=&quot;DOI&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;area-under-the-curve-auc-&quot;&gt;Area Under the Curve (AUC) &lt;a name=&quot;head-auc&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;In machine learning and diagnostic medicine the area under the receiver operating characteristic (ROC) curve or AUC
is a common metric used to evaluate the predictive performance of a model or diagnostic test. New models are often 
bench marked against established models using AUC. Comparing AUCs of new and old models to evaluate improvement is a
 good place to start however, many end their analysis here and believe that simply reporting a higher AUC is 
sufficient. AUC can be misleading as it gives equal weight to the full range of sensitivity and specificity values even 
though a limited range, or specific threshold, may be of practical interest. In this article, we show how to fully 
interrogate new and improved model performance, beyond simple AUC comparisons, as to provide a more comprehensive 
understanding of improvements within the context of a given problem. We also present a coded example, in Python, to
 demonstrate the concepts we present.&lt;/p&gt;

&lt;h3 id=&quot;example-breast-cancer-&quot;&gt;Example: Breast Cancer &lt;a name=&quot;head-bc&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;Code for the following example and useful AUC, NRI, IDI functions can be found at &lt;a href=&quot;https://github.com/LambertLeong/AUC_NRI_IDI_python_functions&quot;&gt;github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Breast cancer is the leading cause of cancer death in women world wide. Early detection has helped to lower the mortality
rate and the earlier a malignancy is identified, the more likely a patient is to survive.  As such, great effort has
been allocated to developing predictive models to better identify cancer.  In this example we use extracted imaging features
to build models to predict malignancy probability. We use data from the 
&lt;a href=&quot;https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+(Diagnostic)&quot; target=&quot;_blank&quot;&gt;Diagnostic Wisconsin Breast Cancer Database&lt;/a&gt;
[&lt;a href=&quot;#ref-uci&quot;&gt;1&lt;/a&gt;] housed at the UCI Machine Learning Repository.&lt;/p&gt;

&lt;p&gt;As mentioned previously, AUC gives equal weight to all thresholds but this may not be practical in the context of 
breast cancer diagnosis. The
 &lt;a href=&quot;https://www.cancer.org/cancer/breast-cancer/screening-tests-and-early-detection/mammograms/understanding-your-mammogram-report.html&quot; target=&quot;_blank&quot;&gt;Breast Imaging Reporting and Data System or (BI-RADS)&lt;/a&gt; 
 [&lt;a href=&quot;#ref-birads&quot;&gt;2&lt;/a&gt;].
provides a course of action for a given probability of malignancy.  In short, if the probability of malignancy is greater
than 2%, a biopsy is recommended. Biopsies are invasive procedures and they can be physically and mentally detrimental to patients.
A new and improved breast model would ideally be better at identifying cancers (sensitivity increase) and reducing false
 positives (specificity increase), preferably below 2% to avoid invasive and unnecessary biopsies.&lt;/p&gt;

&lt;p&gt;We set up the example with the following code snippets.&lt;/p&gt;

&lt;h4 id=&quot;example-set-up&quot;&gt;Example Set up&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-python:&quot;&gt;# Import Modules #
import os
import sys
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import seaborn as sns
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.metrics import roc_auc_score
from sklearn.metrics import roc_auc_score
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After we import the necessary modules, we load the breast cancer data set and split the data into a train and test set.
Note, it is best practice to also create a validation set and we would normally do that but for the sake of this example we will stick with
just a training and test set.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python:&quot;&gt;# Import data # 
data = load_breast_cancer()
# Create DataFrame and Split Data
df = pd.DataFrame(data=data[&apos;data&apos;],columns=data[&apos;feature_names&apos;])
df[&apos;label&apos;]=data[&apos;target&apos;]
x_train, x_test, y_train, y_test = train_test_split(df.iloc[:,:-1], df.iloc[:,-1], test_size=0.40, random_state=123)

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Also for the sake of this example, we will pretend that our reference/bench mark model was built on breast imaging features
pertaining to texture, concave points, smoothness, fractal dimension, and compactness. We will also pretend that the new
 model uses additional imaging biomarkers/features which pertain to  radius, perimeter, area, symmetry, and concavity. 
 In total, the reference model is built using a total of 15 features while the new model is built using 30 features (15 
 features used by the original model and 15 new features). The following code snippet creates to two sets of features.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python:&quot;&gt;# create ref and new model feature sets #
ref_feat, new_feat = [],[]
for i in data[&apos;feature_names&apos;]:
    if &apos;fractal&apos; in i or &apos;smoothness&apos; in i or &apos;texture&apos; in i or &apos;concave&apos; in i or &apos;compactness&apos; in i:
        ref_feat+=[i]
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;modeling&quot;&gt;Modeling&lt;/h4&gt;
&lt;p&gt;We create a reference or “ref model” with 15 features and the “new model” with all 30 features.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python:&quot;&gt;# init models
ref_model = RandomForestClassifier() 
new_model = RandomForestClassifier() 
# fit models to train data
ref_model.fit(x_train[ref_feat], y_train)
new_model.fit(x_train[new_feat], y_train)
# make predictions on test data
test_ref_pred=ref_model.predict_proba(x_test[ref_feat])
test_new_pred=new_model.predict_proba(x_test[new_feat])
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;issues-with-comparing-models-aucs-&quot;&gt;Issues with Comparing Models AUCs &lt;a name=&quot;head-issue&quot;&gt;&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;We previously mentioned that comparing AUCs is a good starting point. We do that here to get an idea of how the new model
performed with respect to our reference model. We use the following custom function to visualize ROC curves and confidence intervals (CI).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python:&quot;&gt;def bootstrap_results(y_truth, y_pred,num_bootstraps = 1000):
    n_bootstraps = num_bootstraps
    rng_seed = 42  # control reproducibility
    y_pred=y_pred
    y_true=y_truth
    rng = np.random.RandomState(rng_seed)
    tprs=[]
    fprs=[]
    aucs=[]
    threshs=[]
    base_thresh = np.linspace(0, 1, 101)
    for i in range(n_bootstraps):
        # bootstrap by sampling with replacement on the prediction indices
        indices = rng.randint(0, len(y_pred), len(y_pred))
        if len(np.unique(y_true[indices])) &amp;lt; 2:
            # We need at least one positive and one negative sample for ROC AUC
            continue
        fpr, tpr, thresh = metrics.roc_curve(y_true[indices],y_pred[indices])
        thresh=thresh[1:]
        thresh=np.append(thresh,[0.0])
        thresh=thresh[::-1]
        fpr = np.interp(base_thresh, thresh, fpr[::-1])
        tpr = np.interp(base_thresh, thresh, tpr[::-1])
        tprs.append(tpr)
        fprs.append(fpr)
        threshs.append(thresh)
    tprs = np.array(tprs)
    mean_tprs = tprs.mean(axis=0)  
    fprs = np.array(fprs)
    mean_fprs = fprs.mean(axis=0)
    return base_thresh, mean_tprs, mean_fprs

def get_auc_ci(y_truth, y_pred,num_bootstraps = 1000):
    n_bootstraps = num_bootstraps
    rng_seed = 42  # control reproducibility
    bootstrapped_scores = []
    y_pred=y_pred
    y_true=y_truth
    rng = np.random.RandomState(rng_seed)
    tprs=[]
    aucs=[]
    base_fpr = np.linspace(0, 1, 101)
    for i in range(n_bootstraps):
        # bootstrap by sampling with replacement on the prediction indices
        indices = rng.randint(0, len(y_pred), len(y_pred))
        if len(np.unique(y_true[indices])) &amp;lt; 2:
            # We need at least one positive and one negative sample for ROC AUC
            continue
        score = roc_auc_score(y_true[indices], y_pred[indices])
        bootstrapped_scores.append(score)
        fpr, tpr, _ = metrics.roc_curve(y_true[indices],y_pred[indices])
        roc_auc = metrics.auc(fpr, tpr)
        aucs.append(roc_auc)
        tpr = np.interp(base_fpr, fpr, tpr)
        tpr[0] = 0.0
        tprs.append(tpr)
    tprs = np.array(tprs)
    mean_tprs = tprs.mean(axis=0)
    std = tprs.std(axis=0)
    mean_auc = metrics.auc(base_fpr, mean_tprs)
    std_auc = np.std(aucs)
    tprs_upper = np.minimum(mean_tprs + std*2, 1)
    tprs_lower = mean_tprs - std*2
    return base_fpr, mean_tprs, tprs_lower, tprs_upper, mean_auc, std_auc

def plot_auc(truth, reference_model, new_model,n_bootstraps=1000, save=False):
    y_truth = truth
    ref_model = reference_model
    new_model = new_model
    ref_fpr, ref_tpr, ref_thresholds = metrics.roc_curve(y_truth, ref_model)
    new_fpr, new_tpr, new_thresholds = metrics.roc_curve(y_truth, new_model)
    ref_auc, new_auc = metrics.auc(ref_fpr, ref_tpr), metrics.auc(new_fpr, new_tpr)
    print(&apos;ref auc =&apos;,ref_auc, &apos;\newn auc = &apos;, new_auc)   
    base_fpr_ref, mean_tprs_ref, tprs_lower_ref, tprs_upper_ref, mean_auc_ref, std_auc_ref=get_auc_ci(y_truth, ref_model,n_bootstraps)
    base_fpr_new, mean_tprs_new, tprs_lower_new, tprs_upper_new, mean_auc_new, std_auc_new=get_auc_ci(y_truth, new_model,n_bootstraps)
    plt.figure(figsize=(8, 8))
    lw = 2
    plt.plot(ref_fpr, ref_tpr, color=&apos;blue&apos;,
             lw=lw, label=&apos;Reference raw ROC (AUC = %0.2f)&apos; % ref_auc, linestyle=&apos;--&apos;)
    plt.plot(base_fpr_ref, mean_tprs_ref, &apos;b&apos;, alpha = 0.8, label=r&apos;Reference mean ROC (AUC=%0.2f, CI=%0.2f-%0.2f)&apos; % (mean_auc_ref, (mean_auc_ref-2*std_auc_ref),(mean_auc_ref+2*std_auc_ref)),)
    plt.fill_between(base_fpr_ref, tprs_lower_ref, tprs_upper_ref, color = &apos;b&apos;, alpha = 0.2)
    plt.plot(new_fpr, new_tpr, color=&apos;darkorange&apos;,
             lw=lw, label=&apos;New raw ROC (AUC = %0.2f)&apos; % new_auc, linestyle=&apos;--&apos;)
    plt.plot(base_fpr_new, mean_tprs_new, &apos;darkorange&apos;, alpha = 0.8, label=r&apos;New mean ROC (AUC=%0.2f, CI=%0.2f-%0.2f)&apos; % (mean_auc_new,(mean_auc_new-2*std_auc_new),(mean_auc_new+2*std_auc_new)),)
    plt.fill_between(base_fpr_new, tprs_lower_new, tprs_upper_new, color = &apos;darkorange&apos;, alpha = 0.2)
    plt.plot([0, 1], [0, 1], color=&apos;gray&apos;, lw=lw, linestyle=&apos;--&apos;)
    plt.xlim([0.0, 1.0])
    plt.ylim([0.0, 1.0])
    plt.xlabel(&apos;1 - Specificity&apos;, fontsize=18)
    plt.ylabel(&apos;Sensitivity&apos;, fontsize=18)
    plt.legend(loc=&quot;lower right&quot;, fontsize=13)
    plt.gca().set_aspect(&apos;equal&apos;, adjustable=&apos;box&apos;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We run the following to generate AUC plots.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python:&quot;&gt;plot_auc(y_test.values,test_ref_pred[:,1],test_new_pred[:,1],n_bootstraps=100)
&lt;/code&gt;&lt;/pre&gt;
&lt;center&gt;
    &lt;a name=&quot;auc_plot&quot;&gt;&lt;/a&gt;
  &lt;img src=&quot;/assets/images/essays/auc_idi_nri/auc_ci_example.png&quot; width=&quot;70%&quot; alt=&quot;breast models AUC with confidence intervals&quot; /&gt;
&lt;br /&gt;
  	Figure 1: AUC curves with confidence intervals calculated using bootstrapping
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Mean curves and the 95% confidence interval in &lt;a href=&quot;#auc_plot&quot;&gt;Figure 1.&lt;/a&gt; were calculated via 100 rounds of bootstrapping, see code above. The reference (blue curve)
and new model (orange curve) produce similar AUC at 0.99 and 0.99, respectively. The confidence interval is slightly narrower
for the new model. Overall, it is difficult to draw any meaningful conclusion from the AUC curves alone and it would appear
that the new model with additional features did little to nothing to improve malignancy predictions.&lt;/p&gt;

&lt;h2 id=&quot;beyond-the-area-under-the-curve-&quot;&gt;Beyond the Area Under the Curve &lt;a name=&quot;head-beyond&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;Our example in &lt;a href=&quot;#auc_plot&quot;&gt;Figure 1.&lt;/a&gt; demonstrates how using only AUC can be limiting and suggest that analysis needs to 
 go beyond simile AUC comparision. We present two additional metrics which are commonly used to asses the impact of new features or biomarkers on a model.
These metrics include the net reclassification index (NRI) and the integrated discrimination improvement (IDI) [&lt;a href=&quot;#ref-pencina&quot;&gt;3&lt;/a&gt;]. These 
two metrics will help in understanding the actual differences in the two models that may not be obvious in &lt;a href=&quot;#auc_plot&quot;&gt;Figure 1.&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;net-reclassification-index-nri-&quot;&gt;Net Reclassification Index (NRI) &lt;a name=&quot;head-nri&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;The NRI is derived by summing the number of NRI&lt;sub&gt;events&lt;/sub&gt; and NRI&lt;sub&gt;nonevents&lt;/sub&gt;.  In our example, events
 are synonymous to patients with cancer or maligancies and NRI&lt;sub&gt;nonevents&lt;/sub&gt; are synonymous to patients who
 do have benign findings. The NRI&lt;sub&gt;events&lt;/sub&gt; is the net proportion of patients with events reassigned to a higher 
 risk category and the NRI&lt;sub&gt;nonevents&lt;/sub&gt; is the number of patients without events reassigned to a lower risk category [&lt;a href=&quot;#ref-pencina2&quot;&gt;4&lt;/a&gt;].
 We compute the NRI using the following Python functions.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-python:&quot;&gt;def check_cat(prob,thresholds):
    cat=0
    for i,v in enumerate(thresholds):
        if prob&amp;gt;v:
            cat=i
    return cat

def make_cat_matrix(ref, new, indices, thresholds):
    num_cats=len(thresholds)
    mat=np.zeros((num_cats,num_cats))
    for i in indices:
        row,col=check_cat(ref[i],thresholds),check_cat(new[i],thresholds)
        mat[row,col]+=1
    return mat
        
def nri(y_truth,y_ref, y_new,risk_thresholds):
    event_index = np.where(y_truth==1)[0]
    nonevent_index = np.where(y_truth==0)[0]
    event_mat=make_cat_matrix(y_ref,y_new,event_index,risk_thresholds)
    nonevent_mat=make_cat_matrix(y_ref,y_new,nonevent_index,risk_thresholds)
    events_up, events_down = event_mat[0,1:].sum()+event_mat[1,2:].sum()+event_mat[2,3:].sum(),event_mat[1,:1].sum()+event_mat[2,:2].sum()+event_mat[3,:3].sum()
    nonevents_up, nonevents_down = nonevent_mat[0,1:].sum()+nonevent_mat[1,2:].sum()+nonevent_mat[2,3:].sum(),nonevent_mat[1,:1].sum()+nonevent_mat[2,:2].sum()+nonevent_mat[3,:3].sum()
    nri_events = (events_up/len(event_index))-(events_down/len(event_index))
    nri_nonevents = (nonevents_down/len(nonevent_index))-(nonevents_up/len(nonevent_index))
    return nri_events, nri_nonevents, nri_events + nri_nonevents 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We input both the reference and new models predictions into the NRI function to calculate the events, nonevents, and total NRI.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-python:&quot;&gt;print(nri(y_test.values,test_ref_pred[:,1],test_new_pred[:,1],[0.02,0.1,0.5,0.95]))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The output from the code above is:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-$bash:&quot;&gt;0.1642857142857143, 0.125, 0.2892857142857143 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It is tempting to state that “the new model reclassified 29% of the patients when compared to the reference model” however,
this would not be an accurate statement nor a proper interpretation of NRI.  Since the NRI is the sum of the proportion of events 
and not events it is possible to have an NRI of 2 or 200%. Stating that the new model reclassified 200% more individuals
 is not possible because it implies that there are suddenly twice as many patients.A more correct interpretation would be
 to state that the new model correctly classified 16% more cancer cases and 13% more benigns when compared to the reference,
 totaling a overall NRI of 29%.&lt;/p&gt;

&lt;p&gt;The NRI show us that adding more features to the new model reclassified both malignant and non-malignant patients.  This
information could not be concluded from AUC alone and may have incorrectly led people to think the models were the same. In a clinical
setting, the new model would have found more cancers which could potentially save more lives. Also, the new model would have
correctly identified more benigns which would translate to less stress for an individual and potentially sparing them from having and invasive procedure like a biopsy.&lt;/p&gt;

&lt;p&gt;Category free or cfNRI is a newer metric and tracks overall movement of event and nonevents, irrespective of class.
For our breast cancer example, the American College of Radiology (ACR) has distinct BI-RADS classes and therefore we do not
find the need to calculate the cfNRI. We provide coded functions to calculate cfNRIs below in the instance that it may
suit you problem.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-python:&quot;&gt;def track_movement(ref,new, indices):
    up, down = 0,0
    for i in indices:
        ref_val, new_val = ref[i],new[i]
        if ref_val&amp;lt;new_val:
            up+=1
        elif ref_val&amp;gt;new_val:
            down+=1
    return up, down

def category_free_nri(y_truth,y_ref, y_new):
    event_index = np.where(y_truth==1)[0]
    nonevent_index = np.where(y_truth==0)[0]
    events_up, events_down = track_movement(y_ref, y_new,event_index)
    nonevents_up, nonevents_down = track_movement(y_ref, y_new,nonevent_index)
    nri_events = (events_up/len(event_index))-(events_down/len(event_index))
    nri_nonevents = (nonevents_down/len(nonevent_index))-(nonevents_up/len(nonevent_index))
    #print(events_up, events_down, len(event_index), nonevents_up, nonevents_down, len(nonevent_index), nri_events, nri_nonevents, nri_events+nri_nonevents)
    return nri_events, nri_nonevents, nri_events + nri_nonevents 
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;integrate-discrimination-index-idi-&quot;&gt;Integrate Discrimination Index (IDI) &lt;a name=&quot;head-idi&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;The IDI is a measure in the change of the discrimination slopes and shows the impact of new biomarkers on a binary predictive
model. The IDI is the sum of the integrated sensitivity (IS) and integrated specificity (IP) and like NRI, it separates
out events and nonevents or in this case cancers and benigns. We use the following code to calculate and plot the IDI curves [&lt;a href=&quot;#ref-pickering&quot;&gt;5&lt;/a&gt;].&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-python:&quot;&gt;def area_between_curves(y1,y2):
    diff = y1 - y2 # calculate difference
    posPart = np.maximum(diff, 0) 
    negPart = -np.minimum(diff, 0) 
    posArea = np.trapz(posPart)
    negArea = np.trapz(negPart)
    return posArea,negArea,posArea-negArea

def plot_idi(y_truth, ref_model, new_model, save=False): 
    ref_fpr, ref_tpr, ref_thresholds = metrics.roc_curve(y_truth, ref_model)
    new_fpr, new_tpr, new_thresholds = metrics.roc_curve(y_truth, new_model)
    base, mean_tprs, mean_fprs=bootstrap_results( y_truth, new_model,100)
    base2, mean_tprs2, mean_fprs2=bootstrap_results( y_truth, ref_model,100)
    is_pos,is_neg, idi_event=area_between_curves(mean_tprs,mean_tprs2)
    ip_pos,ip_neg, idi_nonevent=area_between_curves(mean_fprs2,mean_fprs)
    print(&apos;IS positive&apos;, round(is_pos,2),&apos;IS negative&apos;,round(is_neg,2),&apos;IDI events&apos;,round(idi_event,2))
    print(&apos;IP positive&apos;, round(ip_pos,2),&apos;IP negative&apos;,round(ip_neg,2),&apos;IDI nonevents&apos;,round(idi_nonevent,2))
    print(&apos;IDI =&apos;,round(idi_event+idi_nonevent,2))
    plt.figure(figsize=(10, 10))
    ax=plt.axes()
    lw = 2
    plt.plot(base, mean_tprs, &apos;black&apos;, alpha = 0.5, label=&apos;Events New (New)&apos; )
    plt.plot(base, mean_fprs, &apos;red&apos;, alpha = 0.5, label=&apos;Nonevents New (New)&apos;)
    plt.plot(base2, mean_tprs2, &apos;black&apos;, alpha = 0.7, linestyle=&apos;--&apos;,label=&apos;Events Reference (Ref)&apos; )
    plt.plot(base2, mean_fprs2, &apos;red&apos;, alpha = 0.7,  linestyle=&apos;--&apos;, label=&apos;Nonevents Reference (Ref)&apos;)
    plt.fill_between(base, mean_tprs,mean_tprs2, color=&apos;black&apos;,alpha = 0.1, label=&apos;Integrated Sensitivity (area = %0.2f)&apos;%idi_event)
    plt.fill_between(base, mean_fprs,mean_fprs2, color=&apos;red&apos;, alpha = 0.1, label=&apos;Integrated Specificity (area = %0.2f)&apos;%idi_nonevent)
    
    #&apos;&apos;&apos; #TODO: comment out if not for breast birads
    ### BIRADS Thresholds ###
    plt.axvline(x=0.02,color=&apos;darkorange&apos;,linestyle=&apos;--&apos;,alpha=.5,label=&apos;BI-RADS 3/4a Border (2%)&apos;)
    plt.axvline(x=0.10,color=&apos;green&apos;,linestyle=&apos;--&apos;,alpha=.5,label=&apos;BI-RADS 4a/4b Border (10%)&apos;)
    plt.axvline(x=0.5,color=&apos;blue&apos;,linestyle=&apos;--&apos;,alpha=.5,label=&apos;BI-RADS 4b/4c Border (50%)&apos;)
    plt.axvline(x=0.95,color=&apos;purple&apos;,linestyle=&apos;--&apos;,alpha=.5,label=&apos;BI-RADS 4c/5 Border (95%)&apos;)
    def nri_annotation(plt, threshold):
        x_pos = base[threshold]
        x_offset=0.02
        x_offset2=x_offset
        text_y_offset=0.01
        text_y_offset2=text_y_offset
        if threshold==2:
            text_y_offset=0.04
            text_y_offset2=0.04
            x_offset2=0.05
            print(x_pos+x_offset, (np.mean([mean_tprs2[threshold], mean_tprs[threshold]])+text_y_offset),
                    x_pos, (np.mean([mean_tprs2[threshold], mean_tprs[threshold]])))
        text_y_events=np.mean([mean_tprs2[threshold], mean_tprs[threshold]])+text_y_offset
        text_y_nonevents=np.mean([mean_fprs[threshold], mean_fprs2[threshold]])+text_y_offset2
        plt.annotate(&apos;&apos;, xy=(x_pos+0.02, mean_tprs2[threshold+1]), xycoords=&apos;data&apos;, xytext=(x_pos+0.02, 
                            mean_tprs[threshold]), textcoords=&apos;data&apos;, arrowprops={&apos;arrowstyle&apos;: &apos;|-|&apos;})
        plt.annotate(&apos;NRI$_{events}$ = %0.2f&apos;%(mean_tprs[threshold]-mean_tprs2[threshold]), 
                     xy=(x_pos+x_offset, text_y_events), xycoords=&apos;data&apos;,
                     xytext=(x_pos+x_offset, text_y_events),
                     textcoords=&apos;offset points&apos;, fontsize=15)
        plt.annotate(&apos;&apos;, xy=(x_pos+0.02, mean_fprs[threshold]), xycoords=&apos;data&apos;, xytext=(x_pos+0.02, 
                             mean_fprs2[threshold]), textcoords=&apos;data&apos;, arrowprops=dict(arrowstyle= &apos;|-|&apos;,color=&apos;r&apos;))
        plt.annotate(&apos;NRI$_{nonevents}$ = %0.2f&apos;%(mean_fprs2[threshold]-mean_fprs[threshold]), 
                     xy=(x_pos+x_offset2, text_y_nonevents), xycoords=&apos;data&apos;,
                     xytext=(x_pos+x_offset2, text_y_nonevents), 
                     textcoords=&apos;offset points&apos;, fontsize=15)
        print(&apos;Threshold =&apos;,round(x_pos,2),&apos;NRI events =&apos;,round(mean_tprs[threshold]-mean_tprs2[threshold],4),
              &apos;NRI nonevents =&apos;,round(mean_fprs2[threshold]-mean_fprs[threshold],4),&apos;Total =&apos;,
              round((mean_tprs[threshold]-mean_tprs2[threshold])+(mean_fprs2[threshold]-mean_fprs[threshold]),4))
    nri_annotation(plt,2)
    nri_annotation(plt,10)
    nri_annotation(plt,50)
    nri_annotation(plt,95)
    #&apos;&apos;&apos;
    plt.xlim([0.0, 1.10])
    plt.ylim([0.0, 1.10])
    ax.spines[&apos;right&apos;].set_visible(False)
    ax.spines[&apos;top&apos;].set_visible(False)
    plt.xlabel(&apos;Calculated Risk&apos;, fontsize=18)
    plt.ylabel(&apos;Sensitivity (black), 1 - Specificity (red)&apos;, fontsize=18)
    plt.legend(loc=&quot;upper right&quot;, fontsize=11)
    plt.legend(loc=0, fontsize=11,  bbox_to_anchor=(0,0,1.2,.9))
    plt.gca().set_aspect(&apos;equal&apos;, adjustable=&apos;box&apos;)
    #if save:
    #    plt.savefig(&apos;idi_curve.png&apos;,dpi=300, bbox_inches=&apos;tight&apos;)
    look=95
    plt.show()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We run the following command to generate the graph in &lt;a href=&quot;#idi_plot&quot;&gt;Figure 2.&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python:&quot;&gt;plot_idi(y_test.values,test_ref_pred[:,1],test_new_pred[:,1])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Output:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-$bash&quot;&gt;IS positive 3.58 IS negative 0.16 IDI events 3.42
IP positive 4.61 IP negative 0.04 IDI nonevents 4.57
IDI = 7.98
0.04 1.04 0.02 1.0
Threshold = 0.02 NRI events = 0.0 NRI nonevents = 0.2762 Total = 0.2762
Threshold = 0.1 NRI events = -0.008 NRI nonevents = 0.1002 Total = 0.0922
Threshold = 0.5 NRI events = 0.0215 NRI nonevents = 0.0317 Total = 0.0532
Threshold = 0.95 NRI events = 0.1389 NRI nonevents = -0.0136 Total = 0.1252
&lt;/code&gt;&lt;/pre&gt;

&lt;center&gt;
    &lt;a name=&quot;idi_plot&quot;&gt;&lt;/a&gt;
  &lt;img src=&quot;/assets/images/essays/auc_idi_nri/idi_example.png&quot; width=&quot;90%&quot; alt=&quot;Integrated Discrimination Improvement (IDI) index python plots&quot; /&gt;
&lt;br /&gt;
  	Figure 2: IDI curve with calculated NRI at each class or BI-RADS border
&lt;/center&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;The dashed and solid curves represent the reference and new model respectively. In the ideal case, the solid black line would
be moved to the upper right indicating the most improvement to sensitivity and the red line would be lowered to the bottom
right indicating the most improved specificity.  The area between the black and red curves equate to the IS and IP and the total
sum of the black and red area equates to the IDI. IDI provides more information that the AUC curves especially with respects to the 
orange dashed vertical line or the BI-RADS 3/4a border. At this border, the IP or red area is large which indicates that the 
new model was able to better predict benigns. This border is particularly interesting because it is recommended that all
patients with BI-RADS 4 or greater receive biopsies [&lt;a href=&quot;#ref-leong&quot;&gt;6&lt;/a&gt;]. The large area at the 3/4a border shows that adding new features to the new 
model increase specificity and potentially prevented 28% more people (NRI&lt;sub&gt;nonevents&lt;/sub&gt;=0.28) from being unnecessarily biopsied.&lt;/p&gt;

&lt;h2 id=&quot;final-thoughts-&quot;&gt;Final Thoughts &lt;a name=&quot;head-final&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;AUC is a good metric but does not provide all the information needed for a comprehensive analysis of the impact of new biomarkers and
models.  The NRI and IDI should be used to complement AUC findings and interpretations. As a data scientist and cancer
researcher who uses Python, it was difficult to find functions and code snippets that computed and plotted NRI and IDI as presented here.
This was my motivation for posting this and I hope that my code can help other in their research, discoveries, and pursuit of 
better health care solutions.&lt;/p&gt;

&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;

&lt;p&gt;&lt;a name=&quot;ref-uci&quot; href=&quot;https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+(Diagnostic)&quot; target=&quot;_blank&quot;&gt;[1]&lt;/a&gt; 
Dua, D. and Graff, C, (2019), Irvine, CA: University of California, School of Information and Computer Science, UCI Machine Learning Repository [http://archive.ics.uci.edu/ml].&lt;/p&gt;

&lt;p&gt;&lt;a name=&quot;ref-birads&quot; href=&quot;https://www.cancer.org/cancer/breast-cancer/screening-tests-and-early-detection/mammograms/understanding-your-mammogram-report.html&quot; target=&quot;_blank&quot;&gt;[2]&lt;/a&gt; 
Understanding mammogram reports: Mammogram results. (n.d.). Retrieved May 06, 2021, from https://www.cancer.org/cancer/breast-cancer/screening-tests-and-early-detection/mammograms/understanding-your-mammogram-report.html&lt;/p&gt;

&lt;p&gt;&lt;a name=&quot;ref-pencina&quot; href=&quot;https://onlinelibrary.wiley.com/doi/abs/10.1002/sim.2929&quot; target=&quot;_blank&quot;&gt;[3]&lt;/a&gt; Pencina, M. J., D’Agostino Sr, R. B., D’Agostino Jr, R. B., &amp;amp; Vasan, R. S., Evaluating the added
 predictive ability of a new marker: from area under the ROC curve to reclassification and beyond, 
 (2008), Statistics in medicine, 27(2), 157-172.&lt;/p&gt;

&lt;p&gt;&lt;a name=&quot;ref-pencina2&quot; href=&quot;https://onlinelibrary.wiley.com/doi/abs/10.1002/sim.4085&quot; target=&quot;_blank&quot;&gt;[4]&lt;/a&gt; Pencina, M. J., D’Agostino Sr, R. B., &amp;amp; Steyerberg, E. W., Extensions of net reclassification improvement 
calculations to measure usefulness of new biomarkers, (2011), Statistics in medicine, 30(1), 11-21.&lt;/p&gt;

&lt;p&gt;&lt;a name=&quot;ref-pickering&quot; href=&quot;https://cjasn.asnjournals.org/content/7/8/1355&quot; target=&quot;_blank&quot;&gt;[5]&lt;/a&gt; Pickering, J. W., &amp;amp; Endre, Z. H., New metrics for assessing diagnostic potential of candidate biomarkers,
 (2012), Clinical Journal of the American Society of Nephrology, 7(8), 1355-1364.&lt;/p&gt;

&lt;p&gt;&lt;a name=&quot;ref-leong&quot; href=&quot;https://www.nature.com/articles/s43856-021-00024-0&quot; target=&quot;_blank&quot;&gt;[6]&lt;/a&gt; Leong, L., Malkov, S., Drukker, K., Niell, B., Sadowski, P., Wolfgruber, T., … &amp;amp; Shepherd, J., Dual-energy three
  compartment breast imaging (3CB) for novel compositional biomarkers to improve detection of malignant lesions, (2021).&lt;/p&gt;

</description>
        <pubDate>Sat, 01 May 2021 00:00:00 +0000</pubDate>
        <link>https://www.lambertleong.com/thoughts/auc-idi-nri</link>
        <guid isPermaLink="true">https://www.lambertleong.com/thoughts/auc-idi-nri</guid>
        
        <category>AUC</category>
        
        <category>IDI</category>
        
        <category>NRI</category>
        
        <category>Python</category>
        
        <category>Data</category>
        
        <category>Science</category>
        
        <category>area</category>
        
        <category>under</category>
        
        <category>the</category>
        
        <category>curve</category>
        
        <category>ROC</category>
        
        <category>Integrated</category>
        
        <category>discrimination</category>
        
        <category>improvement</category>
        
        <category>net</category>
        
        <category>reclassification</category>
        
        <category>index</category>
        
        <category>breast</category>
        
        <category>cancer</category>
        
        
        <category>thoughts</category>
        
      </item>
    
      <item>
        <title>Correlations Between Social Media and the 2020 Presidential Election</title>
        <description>&lt;p&gt;&lt;strong&gt;TLDR:&lt;/strong&gt;  Too Long, Didn’t Read&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Well, we all know the results of the election and social media had an influence on voter turn out.&lt;/li&gt;
  &lt;li&gt;Republican related tweets out numbered democratic related tweets and may indicate higher tweet frequency, more users, and/or people are more inclinded to tweet 
republican related tweets.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Here is the data, make your own conclusions.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;Oscar Wilde once wrote “The only thing worse than being talked about is not being talked about”. This is
along the idea that any press is good press and with Trump in 2016 this seemed to be the case.  The 2016 election showed
 us that social media can have an effect on who become president and runs the country. We also learned in 2016 that polls
 and approval ratings just didn’t cut it and it doesn’t tell us much.  After all, Trump polled lower in 2016 and then who 
 got to run the country?  Here we
  look at trending twitter hashtags and terms as they relate to one of the two major political parties leading up to the 2020 election.
  Looking at other data sources and taking different angles can always provide valuable insight to the topic at hand.&lt;/p&gt;

&lt;p&gt;We gathered the top 50 trending topics on Twitter each day for the past year. These topics are presented
in the form of hashtages (#) and trending words, terms, or phrases.  With this data we can investigate
how many days a topic was trending as well as the changes in total tweet volume for a topic.  Tweet data was 
provided by &lt;a href=&quot;https://twitter.com/igetthetags&quot;&gt;@igetthetags&lt;/a&gt; &lt;img src=&quot;http://i.imgur.com/wWzX9uB.png (twitter icon without padding)&quot; alt=&quot;Twitter&quot; /&gt;.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tweets Containing:&lt;/th&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Volume&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Biden&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;1,042,926&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Harris&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;167,056&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Trump&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;7,263,062&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Pence&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;268,170&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;br /&gt;
We take no political side and remain objective in our exploration.  In addition, no sentiment
analysis was done on all the tweets to determine if they were for or against a particular political party.
Hence, we reiterate that any press is good press and consider all mentions to be positive for one party or another. We used particular search terms to classify a trending
topic into one of two classes; republican or democrat. A hashtag is categorized as democratic if it 
contains any of the following words: &lt;span style=&quot;color:blue&quot;&gt;‘joebiden’, ‘biden’, ‘kamalaharris’,
‘harris’, ‘democrat’&lt;/span&gt;.  A hashtag is categorized as republican if it contains any of the 
following words: &lt;span style=&quot;color:red&quot;&gt;‘donaldtrump’, ‘trump’, ‘mikepence’, ‘pence’, ‘republican’&lt;/span&gt;
. Remember, hashtags do not contain spaces and thus our classification terms do not as well.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/essays/election_tags/election2020_total.png&quot; width=&quot;70%&quot; alt=&quot;Total tweet political election volume&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The republicans appear to be ahead with respect to social media “buzz”.  Several events and news have
instigated many tweets.  Below is a timeline of important events or news and the corresponding tweet volumes colored by political party.&lt;/p&gt;

&lt;!--div class=&quot;zoom&quot;&gt;
    &lt;img id=&quot;test&quot; src=&quot;/assets/images/essays/hawaii_covid/hawaii_covid19_case_timeline2.png&quot; width=&quot;100%&quot;
      height=&quot;auto&quot; alt=&quot;Hawaii COVID-19 Case Timeline&quot;&gt;
&lt;/div--&gt;

&lt;p&gt;&lt;a href=&quot;/assets/images/essays/election_tags/election2020_tag_timeline.png&quot;&gt;&lt;strong&gt;View Full Case Chart HERE&lt;/strong&gt;&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/p&gt;
&lt;div class=&quot;img-magnifier-container&quot;&gt;
  &lt;img id=&quot;myimage1&quot; src=&quot;/assets/images/essays/election_tags/election2020_tag_timeline2.png&quot; width=&quot;100%&quot; height=&quot;auto&quot; alt=&quot;Hashtag Election Timeline&quot; /&gt;
&lt;/div&gt;
&lt;script&gt;
/* Execute the magnify function: */
magnify(&quot;myimage1&quot;, 2.5);
/* Specify the id of the image, and the strength of the magnifier glass: */
&lt;/script&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;In addition to political classification, we looked at some interesting tweet topics that had high volumes.  The terms
in the following table stemmed from very polarizing events and spurred many political related tweets.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tweets Containing:&lt;/th&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Volume&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Debate&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;3,516,092&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Election&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;467,029&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;BLM&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;11,295&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;BlackLives&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;3,322,864&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Vote&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;1,778,889&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Democracy&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;1,172,879&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;The corona virus or COVID19 was a difficult obstacle that the world faced in 2020.  It was also 
a “hot” topic that sparked many conversations and tweets with respect to the virus as well as 
politics.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/images/essays/election_tags/covid_tags2020.png&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;View Final Count Chart HERE&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/essays/election_tags/covid_tag.gif&quot; width=&quot;69%&quot; alt=&quot;Covid19 corona virus tweet volume 2020&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Despite your political leanings, you can admit that the data is interesting.  Social media is a powerful
information tool and keeping a finger on the pulse may be a good idea.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;More Data and Interpretation Coming Soon&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;!-- Icons --&gt;

</description>
        <pubDate>Tue, 03 Nov 2020 00:00:00 +0000</pubDate>
        <link>https://www.lambertleong.com/thoughts/election2020-social-media-trends</link>
        <guid isPermaLink="true">https://www.lambertleong.com/thoughts/election2020-social-media-trends</guid>
        
        <category>election</category>
        
        <category>president</category>
        
        <category>2020</category>
        
        <category>democrat</category>
        
        <category>republican</category>
        
        <category>twitter</category>
        
        <category>hashtag</category>
        
        
        <category>thoughts</category>
        
      </item>
    
  </channel>
</rss>
