<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Felipe Valencia-Clavijo on Medium]]></title>
        <description><![CDATA[Stories by Felipe Valencia-Clavijo on Medium]]></description>
        <link>https://medium.com/@felipevalencla?source=rss-790adc816552------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*r7a1xb5XYeU5-e76HWcaZg.jpeg</url>
            <title>Stories by Felipe Valencia-Clavijo on Medium</title>
            <link>https://medium.com/@felipevalencla?source=rss-790adc816552------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 18:50:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@felipevalencla/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[One Year of Anchors in the Machine: Following the Questions Beyond the Original Paper]]></title>
            <link>https://medium.com/dataplicada/one-year-of-anchors-in-the-machine-following-the-questions-beyond-the-original-paper-06ce131a0837?source=rss-790adc816552------2</link>
            <guid isPermaLink="false">https://medium.com/p/06ce131a0837</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[ai-safety]]></category>
            <category><![CDATA[explainable-ai]]></category>
            <category><![CDATA[behavioral-economics]]></category>
            <dc:creator><![CDATA[Felipe Valencia-Clavijo]]></dc:creator>
            <pubDate>Thu, 12 Nov 2026 00:44:39 GMT</pubDate>
            <atom:updated>2026-11-12T00:44:39.740Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Reflections on anchoring bias in large language models, the research it connects to, and the new questions emerging across mechanistic interpretability, AI reliability, and agentic systems.</em></p><p>A year ago, on November 7, 2025, I shared a preprint called <a href="https://arxiv.org/abs/2511.05766"><em>Anchors in the Machine: Behavioral and Attributional Evidence of Anchoring Bias in LLMs</em></a>.</p><p>The research began with a question at the intersection of two fields that have long fascinated me: behavioural economics and artificial intelligence.</p><p><strong>If humans are susceptible to cognitive biases when making judgments, what happens when we examine similar phenomena in large language models? And can we investigate not only whether those biases appear, but also how different parts of a prompt contribute to them?</strong></p><p>One year later, I’ve released a second, more concise version of the paper, with improved visualisations derived from the presentation I did at the Behavioral Clones Workshop and a necessary correction to the attribution terminology used in the original version.</p><p>But something else has happened that I find particularly rewarding.</p><p>I’ve identified six research papers that have cited <em>Anchors in the Machine</em>, including work published in conference proceedings and other studies available as preprints.</p><p>Six citations might seem like a modest milestone in the broader academic landscape. For me, however, the most interesting part isn’t the number.</p><p>It’s discovering the questions other researchers are asking.</p><p>Some are investigating the internal computational pathways associated with anchoring. Others are exploring confidence and robustness, the reliability of AI judges, evidence-based agentic reasoning, and even how historical information can influence the behaviour of AI agents interacting in economic markets.</p><p>These papers differ considerably in their objectives, methods, and findings. They also engage with my work in different ways: some directly discuss its attributional approach, while others reference it as part of the growing literature on anchoring and prompt sensitivity.</p><p>Reading them has reminded me of something I find beautiful about research: <strong>an idea does not have to remain confined to the question that originally motivated it.</strong></p><p>I wanted to take this anniversary as an opportunity to acknowledge these researchers, highlight what I found interesting in their work, and reflect on where these connections might lead.</p><h3>Where it started: Anchoring bias and the behaviour of language models</h3><p>Anchoring bias is one of the classic findings in behavioural economics and cognitive psychology.</p><p>In their influential 1974 work, Amos Tversky and Daniel Kahneman demonstrated how exposure to an initial numerical value can influence subsequent estimates, even when that value is arbitrary.</p><p>The phenomenon raises an intriguing question for artificial intelligence.</p><p>LLMs are not human decision-makers. They do not necessarily possess the psychological mechanisms responsible for human biases. Yet their outputs can display patterns that resemble established cognitive biases.</p><p>In <em>Anchors in the Machine</em>, I examined anchoring using a framework that combined behavioural measurement with attributional analysis.</p><p>The behavioural component investigated how numerical anchors influenced model responses. The attributional component examined how structured elements of the prompt contributed to the probabilities assigned to potential answers.</p><p>The motivation was to move beyond observing that a model’s answer changes and begin examining the contribution of the information it receives.</p><p>One way to illustrate this is through the following visualisation from the revised paper, which brings both perspectives together using Google’s Gemma-2B model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fT7lKubqh6H--YyjS285yg.png" /><figcaption><em>Figure — Behavioural anchoring and Banzhaf attribution in Gemma-2B.</em> Changing an irrelevant numerical anchor from 10 (orange) to 65 (blue) shifted the model’s probability-weighted expected estimate from 23.4% to 52.1%. The visualisation combines candidate answers, their log-probabilities, and Banzhaf attributions measuring the contribution of the anchor information.</figcaption></figure><p>Although the underlying question remained the same, changing an irrelevant number substantially shifted the model’s predicted distribution of answers.</p><p>But the figure also reveals something beyond the behavioural effect. By examining the probabilities assigned to different possible answers alongside their Banzhaf attributions, we can investigate not only how the model’s predictions change, but also how the anchor information contributes to those predictions.</p><p>This distinction matters because two models could exhibit similar behavioural responses to an anchor while displaying very different attributional patterns. Observing human-like behaviour, therefore, does not necessarily mean that the underlying processes are comparable.</p><p>An important distinction is that prompt-level attribution is not the same as identifying the internal neural circuits responsible for a behaviour. The study provided behavioural and attributional evidence, not a complete mechanistic explanation.</p><p>That distinction becomes especially interesting when looking at subsequent research.</p><h3>A memorable milestone: The Behavioral Clones Workshop at the Max Planck Institute</h3><p>Another meaningful moment in this first year was the opportunity to share my research with the interdisciplinary community brought together by the <a href="https://machinebehavior.science/behavioral-clones-ws-26">Behavioral Clones Workshop</a>, part of the Machine+Behavior 2026 conference.</p><p>Held on May 20, 2026, at the Max Planck Institute for Human Development in Berlin, the workshop explored the potential of AI systems to model human decision-making and social behaviour.</p><p>Its central themes included the use of behavioural clones as instruments for understanding human behaviour, as foundations for studying machine behaviour, and as tools for large-scale social simulation.</p><p>I submitted <em>Anchors in the Machine</em> for consideration as a contributed talk, and I was genuinely happy and grateful that it was accepted.</p><p>My presentation was titled:</p><p><strong>When Behavioral Similarity Misleads: Anchoring as a Behavioral Clone of Human Judgment in LLMs</strong></p><p>For the workshop, I approached my research through a slightly different lens.</p><p>Rather than focusing exclusively on whether language models exhibit anchoring bias, I considered what such findings tell us about the reliability of LLMs as behavioural surrogates for humans.</p><p>The central question was:</p><p><strong>If an LLM reproduces a pattern of human judgment, does that necessarily mean it arrives at that behaviour through comparable processes?</strong></p><p>Using the anchoring paradigm, I explored how models could exhibit human-like shifts in numerical judgments while showing different patterns of attributional sensitivity.</p><p>Some models produced behavioural effects comparable to those observed in human studies but displayed relatively diffuse attribution patterns. Others showed stronger attributional sensitivity without correspondingly large behavioural shifts.</p><p>This dissociation between observable behaviour and attributional evidence was an important part of the presentation.</p><p>The broader implication was that behavioural similarity alone may be insufficient to establish the fidelity of an AI system intended to model human judgment.</p><p>I was particularly grateful for the opportunity to contribute to a programme bringing together researchers from psychology, computer science, economics, and other disciplines.</p><p>The <a href="https://center-for-humans-and-machines.github.io/behavioral-clones-2026/">workshop programme</a> included presentations and research contributions from scholars affiliated with institutions such as the Max Planck Institute for Human Development, the World Bank Group, the University of Oxford, University College Dublin, Humboldt-Universität zu Berlin, ETH Zurich, Helmholtz Munich, University College London, and many others.</p><p>The contributed talks, invited presentations, lightning talks, and poster session reflected the breadth of questions emerging around the use of AI to model human behaviour.</p><p>What I found particularly encouraging was the opportunity to see my own research question situated alongside work addressing behavioural simulation, human–machine alignment, psychometrics, social interaction, and the evaluation of AI-generated representations of human judgment.</p><p>These are different problems, but they share an important concern: how can we distinguish meaningful behavioural fidelity from superficial similarity?</p><p>The workshop also brought together a remarkably interdisciplinary community. As a <a href="https://www.kambeitzlab.com/news/2026-05-21-behavioural-clones-workshop/">reflection from the Kambeitz Lab</a> beautifully captured, psychologists, computer scientists, economists, and even a psychiatrist were united by their interest in the potential of LLMs for modelling human behaviour.</p><p>I am grateful to the organisers, Levin Brinkmann and Dirk Wulff, and to the broader research community for creating a space for these conversations.</p><p>Preparing the contributed talk also gave me an opportunity to revisit how I communicated my findings.</p><p>Several of the visualisations developed for the presentation subsequently informed the more concise second version of <em>Anchors in the Machine</em>.</p><p>In that sense, the workshop contributed not only to how I thought about the broader implications of the research, but also to how I presented its results.</p><p>It reinforced a lesson that has stayed with me throughout this year:</p><p><strong>Reproducing a behaviour is not necessarily the same as reproducing the processes behind it.</strong></p><p>That distinction also provides an interesting connection to the research that has since referenced my paper.</p><h3>1. From observing anchoring to investigating its internal pathways</h3><p>One of the papers I was particularly pleased to discover was <a href="https://arxiv.org/abs/2606.12818"><em>Localizing Anchoring Pathways in Language Models</em></a>, by Hillary N. Owusu, Sarah Wiegreffe, and Naomi H. Feldman at the University of Maryland.</p><p>Their work asks an important question: <strong>where, within a language model, is anchor-sensitive information carried?</strong></p><p>Rather than focusing only on whether the final answer changes, the researchers investigate computational pathways associated with the influence of irrelevant numerical information.</p><p>Using circuit-localization techniques, they compare methods that identify individual model components with approaches that examine connections between components.</p><p>One of their findings is that edge-level methods recover the anchoring-related signal more faithfully than node-level approaches. They also find that circuits associated with low and high anchors show considerable overlap within a given model, while instruction tuning can change which specific pathways are most important.</p><p>What I found especially meaningful was how they situated their work in relation to earlier research.</p><p>They explicitly recognised <em>Anchors in the Machine</em> as an example of structured prompt-field attribution used to quantify the influence of anchor information on model log-probabilities.</p><p>Their study then examines a different level of explanation: the pathways within the model that carry an anchor-sensitive signal.</p><p>I see these approaches as complementary.</p><p>Prompt attribution can help us understand which information contributes to an observed effect. Circuit localization can help investigate how that information is processed internally.</p><p>Together, they point toward a broader research direction: connecting behavioural observations, attributional evidence, and mechanistic analysis.</p><p>For me, this is one of the most exciting possibilities emerging in the field.</p><h3>2. Confidence, correctness, and resistance to anchoring</h3><p>Another fascinating contribution comes from Hillary N. Owusu and Naomi H. Feldman in <a href="https://aclanthology.org/2026.acl-short.16/"><em>Anchoring Depends on Confidence and Post-Training in Language Models</em></a>, published at ACL 2026.</p><p>Their research investigates whether susceptibility to numerical anchoring depends on how confident a language model is in its initial answer.</p><p>One might expect models that possess the correct factual knowledge to be more resistant to irrelevant numerical information.</p><p>Their findings suggest something more nuanced.</p><p>Models with concentrated, high-confidence answer distributions can resist anchoring even when their initial answers are incorrect.</p><p>In other words, <strong>resistance to an irrelevant anchor is not necessarily evidence of factual accuracy.</strong></p><p>The authors also examine differences among base, instruction-tuned, and distilled models, finding that post-training affects the relationship between confidence and anchoring susceptibility. They additionally report asymmetric effects, with high numerical anchors generally exerting stronger influence than low ones.</p><p>Their paper references <em>Anchors in the Machine</em> among earlier studies documenting anchoring effects in LLMs.</p><p>What I find particularly valuable here is the distinction between stability and correctness.</p><p>A system that resists external influence isn’t necessarily right. Sometimes, it may simply be stubbornly wrong.</p><p>For practical AI evaluation, this raises an important question: how should we assess robustness when confidence, accuracy, and susceptibility to misleading context do not necessarily move together?</p><h3>3. When language models become judges</h3><p>The relevance of anchoring becomes particularly consequential when language models are no longer simply answering questions, but evaluating other people’s work.</p><p>In <a href="https://doi.org/10.21203/rs.3.rs-10688342/v1"><em>Suggestible Judges: Asymmetric Conformity in Large Language Model Adjudication</em></a>, Divyansh Maiwar Singh, Dhruvish Shah, Rachit Garg, Anshul Gupta, and Gaurav V. Londhe examine how LLM judges respond to labels provided by human annotators.</p><p>Imagine two annotators who disagree about whether a statement should receive a particular classification.</p><p>An LLM is asked to resolve the disagreement. But what happens if the model sees one annotator’s suggested answer before making its own judgment?</p><p>The authors investigate this question using controlled experimental conditions and multiple model families.</p><p>They find that some judges are susceptible to the presented labels, with effects that depend on the model and the value of the label. Importantly, they distinguish manipulability from accuracy, because their principal dataset does not provide independent ground truth against which every judgment can be assessed.</p><p>Their paper cites <em>Anchors in the Machine</em> as part of the literature demonstrating anchoring effects in language models, while recognising that their adjudication setting is different from conventional numerical estimation.</p><p>This is an important distinction, but also a fascinating connection.</p><p><strong>What begins as an apparently simple question about irrelevant information affecting a numerical estimate becomes a broader question about whether AI systems can make independent judgments when exposed to someone else’s conclusions.</strong></p><p>As LLM-based evaluation becomes increasingly common, understanding these vulnerabilities is essential.</p><h3>4. Anchoring and evidence-dependent agentic reasoning</h3><p>A different connection appears in <a href="https://doi.org/10.1007/978-3-032-40374-2_15"><em>NEAT: Agentic Interpretation: Lattice-Structured Evidence for LLM-Based Program Analysis</em></a>, by Jacqueline L. Mitchell and Chao Wang.</p><p>The paper appeared in the proceedings of SAS 2026, published in Springer’s Lecture Notes in Computer Science series.</p><p>Its principal contribution is not about anchoring bias.</p><p>Instead, the authors propose a structured framework for using LLM agents in program analysis, particularly when relevant evidence comes from sources such as documentation, security advisories, metadata, or informal software contracts.</p><p>Rather than relying on a single opaque LLM judgment, their framework decomposes an analysis problem into smaller claims and organises evidence using lattice-based structures and a worklist algorithm.</p><p>The paper cites <em>Anchors in the Machine</em> in its discussion of query design, where the authors consider the trade-offs between asking for different judgments together or separately, including potential anchoring effects.</p><p>I find this connection interesting precisely because the research problem is so different from my original study.</p><p>It illustrates how concerns about prompt sensitivity can become relevant to the architecture of systems designed for more complex tasks.</p><p>The broader question is whether structured evidence management can help make LLM-based reasoning more inspectable, consistent, and auditable.</p><p>The authors present a formal framework, with practical implementation and experimental evaluation left for future work. It is therefore an important design proposal rather than demonstrated evidence that the framework eliminates anchoring.</p><p>Nevertheless, it provides an interesting example of how behavioural reliability questions enter the design of agentic AI systems.</p><h3>5. When evidence is available but not used consistently</h3><p>Arman Nik Khah explores another aspect of reliability in <a href="https://arxiv.org/abs/2609.17226"><em>Easy to Catch a Liar, Hard to Clear an Honest One: Language Models Diagnosing a Corrupted Reward Channel from a Verified Record</em></a>.</p><p>The study examines whether language models can correctly assess a potentially dishonest reward-reporting system when supplied with independent evidence.</p><p>The experimental setup is particularly interesting: different underlying situations can produce identical observed reward histories. A verified record is then introduced that should allow the model to distinguish an honest reporter from a dishonest one.</p><p>The researchers find a striking asymmetry.</p><p>Models perform extremely well at identifying dishonest reporters, yet are substantially less reliable at recognising honest ones. Their answers can also depend on superficial features of the prompt that should not affect the correct conclusion.</p><p>The paper references <em>Anchors in the Machine</em> alongside other work on anchoring and structural sensitivities in autoregressive models.</p><p>Its principal contribution is not another numerical anchoring experiment. Rather, it investigates a different reasoning failure in which surface features interfere with the use of available evidence.</p><p>What interests me is the common concern connecting these research areas:</p><p><strong>Providing an AI system with the information necessary to reach the correct conclusion does not guarantee that it will use that information reliably.</strong></p><p>That question is relevant well beyond numerical estimation. It matters whenever models must distinguish trustworthy evidence from misleading context.</p><h3>6. When markets remember what individual agents no longer see</h3><p>Perhaps the most unexpected connection comes from <a href="https://pys8vc40ox3z7qxp.public.blob.vercel-storage.com/submissions/ai-collusion-research-sprint-2026-10-23-to-2026-10-25/price-afterimage-XdXhb2oZfB7xdIz2OIR1ANDitKKveI.pdf"><em>Price Afterimage: Markets Remember What Agents Forget</em></a>, by Praveen Shukla and Noel Thomas.</p><p>The authors investigate AI agents making pricing decisions in simulated markets.</p><p>Their central question is whether the prices established by language-model agents reflect stable properties of the models or depend on the historical information the agents inherit.</p><p>To investigate this, they introduce different initial price histories and observe what happens after those histories have disappeared from the agents’ immediate prompts.</p><p>In one experimental configuration involving Qwen3–14B, approximately 84% of the initially planted price difference remains long after the original information is no longer visible.</p><p>The researchers show that this persistence is associated with agents responding to one another’s prices. When one participant is replaced by a best-responding rival, the effect nearly disappears.</p><p>The authors call this persistent historical influence a <em>price afterimage</em>.</p><p>Their paper references <em>Anchors in the Machine</em> when discussing numerical anchoring and motivating a control involving irrelevant numbers in their market setting.</p><p>I find this connection particularly intriguing because it moves the discussion from individual predictions toward interacting systems.</p><p>Their results do not establish that the same mechanism observed in numerical anchoring experiments causes price afterimages. Nor do they demonstrate collusion.</p><p>Instead, they raise a related but distinct question worth investigating:</p><p><strong>Can initially influential information become embedded in the ongoing behaviour of an interacting system, even after that information disappears from individual agents’ immediate context?</strong></p><p>For researchers interested in behavioural economics and multi-agent AI, this seems like a particularly promising intersection.</p><h3>What these six papers made me think about</h3><p>Reading these studies together has changed how I think about the broader significance of investigating cognitive bias-like behaviour in language models.</p><p>Not because they all confirm the same finding. They don’t.</p><p>And not because they all directly extend <em>Anchors in the Machine</em>. Their relationships to it vary considerably.</p><p>What connects them is a collection of increasingly important questions about how AI systems respond to information.</p><p>Can we move from observing an effect to understanding the computational pathways associated with it?</p><p>How do confidence and correctness interact with susceptibility to misleading context?</p><p>What happens when a language model evaluates someone else’s judgment rather than generating its own?</p><p>How should agentic systems organise and assess evidence?</p><p>Why might models fail to use information that is sufficient to reach the right answer?</p><p>And how might the history of earlier interactions continue shaping outcomes in multi-agent environments?</p><p>These are distinct research problems. But together they suggest that understanding AI reliability requires looking beyond isolated final outputs.</p><p>We need to study the relationships among inputs, internal computation, evidence, context, and the environments in which AI systems operate.</p><p>For me, this is where the intersection of behavioural science, machine learning, and AI assurance becomes especially interesting.</p><h3>A note on the second version</h3><p>To mark the anniversary, I also released an updated version of <em>Anchors in the Machine</em>.</p><p>The revision includes improved visualisations intended to make the behavioural results and attributional findings easier to interpret.</p><p>It also corrects the naming of the attribution method used in the original manuscript, clarifying its identification as Banzhaf-based attribution.</p><p>I consider corrections and refinements a normal part of research.</p><p>Scientific work should remain open to scrutiny, clarification, and improvement. The objective is not simply to publish a result and leave it untouched, but to represent the evidence as accurately and transparently as possible.</p><p>The revised paper is available under the same <a href="https://arxiv.org/abs/2511.05766">arXiv identifier</a>.</p><h3>A year later: gratitude, curiosity, and the value of sharing research</h3><p>When I first shared <em>Anchors in the Machine</em>, I was motivated by curiosity.</p><p>I wanted to explore a question connecting behavioural economics and artificial intelligence, develop an empirical approach, and hopefully contribute something useful to the wider conversation.</p><p>A year later, I am grateful to see the work referenced by researchers approaching related problems from perspectives I might not have initially anticipated.</p><p>I want to acknowledge the authors of all six papers discussed here. Their contributions are their own, and each brings different methods, insights, and questions to the research landscape.</p><p>I have enjoyed learning from their work, and I hope this short reflection encourages others to explore their papers as well.</p><p>There is something personally rewarding about seeing a research question travel beyond the context in which you first encountered it.</p><p>Of course, citation counts are imperfect indicators of scientific value. A citation does not necessarily imply agreement, methodological dependence, or endorsement.</p><p>But it does provide an opportunity to encounter another researcher’s thinking, understand how they frame a problem, and discover connections that might otherwise remain unnoticed.</p><p>And perhaps that is what I appreciate most about this milestone.</p><p>Research is not only about producing answers.</p><p>It is about making questions available for others to examine, challenge, reinterpret, and carry in directions we could not have predicted.</p><p><strong>A year ago, I shared a paper. Today, I find myself even more interested in the questions surrounding it.</strong></p><p>I’m grateful for the conversations that research makes possible, and curious about where these ones might lead.</p><h3>Papers discussed</h3><ol><li><strong>Valencia-Clavijo, F. (2025; revised 2026).</strong> <em>Anchors in the Machine: Behavioral and Attributional Evidence of Anchoring Bias in Large Language Models.</em> <a href="https://arxiv.org/abs/2511.05766">arXiv:2511.05766</a>.</li><li><strong>Owusu, H. N., Wiegreffe, S., &amp; Feldman, N. H. (2026).</strong> <em>Localizing Anchoring Pathways in Language Models.</em> <a href="https://arxiv.org/abs/2606.12818">arXiv:2606.12818</a>.</li><li><strong>Owusu, H. N., &amp; Feldman, N. H. (2026).</strong> <em>Anchoring Depends on Confidence and Post-Training in Language Models.</em> Proceedings of ACL 2026, Short Papers. <a href="https://aclanthology.org/2026.acl-short.16/">ACL Anthology</a>.</li><li><strong>Singh, D. M., Shah, D., Garg, R., Gupta, A., &amp; Londhe, G. V. (2026).</strong> <em>Suggestible Judges: Asymmetric Conformity in Large Language Model Adjudication.</em> <a href="https://doi.org/10.21203/rs.3.rs-10688342/v1">Research Square</a>.</li><li><strong>Mitchell, J. L., &amp; Wang, C. (2027).</strong> <em>NEAT: Agentic Interpretation: Lattice-Structured Evidence for LLM-Based Program Analysis.</em> In <em>Static Analysis (SAS 2026)</em>, Lecture Notes in Computer Science, vol. 16977. Springer. <a href="https://doi.org/10.1007/978-3-032-40374-2_15">DOI</a>.</li><li><strong>Nik Khah, A. (2026).</strong> <em>Easy to Catch a Liar, Hard to Clear an Honest One: Language Models Diagnosing a Corrupted Reward Channel from a Verified Record.</em> <a href="https://arxiv.org/abs/2609.17226">arXiv:2609.17226</a>.</li><li><strong>Shukla, P., &amp; Thomas, N. (2026).</strong> <em>Price Afterimage: Markets Remember What Agents Forget.</em> <a href="https://pys8vc40ox3z7qxp.public.blob.vercel-storage.com/submissions/ai-collusion-research-sprint-2026-10-23-to-2026-10-25/price-afterimage-XdXhb2oZfB7xdIz2OIR1ANDitKKveI.pdf">Apart Research AI Collusion Sprint report</a>.</li></ol><p><em>Felipe Valencia-Clavijo works at the intersection of data science, behavioural economics, and artificial intelligence, with research interests spanning explainable AI, cognitive biases, and AI reliability. The reflections expressed here are his own.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=06ce131a0837" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dataplicada/one-year-of-anchors-in-the-machine-following-the-questions-beyond-the-original-paper-06ce131a0837">One Year of Anchors in the Machine: Following the Questions Beyond the Original Paper</a> was originally published in <a href="https://medium.com/dataplicada">Dataplicada Insights</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[La verdad detrás de la afirmación de Audiard sobre el “español como lengua de los pobres”]]></title>
            <link>https://medium.com/@felipevalencla/la-verdad-detr%C3%A1s-de-la-afirmaci%C3%B3n-de-audiard-sobre-el-espa%C3%B1ol-como-lengua-de-los-pobres-a2271093de0b?source=rss-790adc816552------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2271093de0b</guid>
            <category><![CDATA[emilia-perez]]></category>
            <category><![CDATA[jacques-audiard]]></category>
            <category><![CDATA[poverty]]></category>
            <category><![CDATA[trending-topic]]></category>
            <category><![CDATA[language]]></category>
            <dc:creator><![CDATA[Felipe Valencia-Clavijo]]></dc:creator>
            <pubDate>Tue, 04 Feb 2025 23:11:19 GMT</pubDate>
            <atom:updated>2025-02-04T23:11:19.087Z</atom:updated>
            <content:encoded><![CDATA[<p>En un comentario, el director francés Jacques Audiard afirmó que <em>“el español es un idioma de países modestos, de países en desarrollo, de los pobres y los migrantes”.</em> Esta declaración generó un debate generalizado, con muchos destacando su sesgo, especialmente dado que varios de los países más pobres del mundo, como Haití, son francófonos.</p><p>Curioso por entender si hay algo de verdad en la afirmación de Audiard y las refutaciones del público sobre los países francófonos también siendo etiquetados de esa manera, decidí explorar los números. Al analizar los datos económicos sobre el PIB per cápita a lo largo del tiempo utilizando los datos de Gapminder, comparé los países de habla francesa y los de habla española para ver si había alguna disparidad significativa en su rendimiento económico.</p><p>¿Los resultados? Los datos son claros: <strong>los países francófonos, en promedio, tienen un PIB per cápita más bajo que los países hispanohablantes.</strong> Los resultados fueron sólidos, con pruebas estadísticas que revelaron una fuerte significancia <em>(p &lt; 0.01)</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*69kgC_9GOpqzlIxoHpmrew.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hJfTn0iWgE6i0XgyrZmyYg.png" /></figure><p>La declaración de Audiard refleja una visión limitada, <strong>probablemente influenciada por sesgos cognitivos que afectan nuestra forma de percibir y juzgar a los demás.</strong> Aquí algunos de los sesgos que pueden explicar su malentendido:</p><ul><li><strong>Sesgo de disponibilidad</strong>: Audiard puede estar asociando el español con la pobreza debido a su posible exposición a ciertas comunidades vulnerables de habla hispana, lo que podría llevar a esta visión distorsionada.</li><li><strong>Sesgo de confirmación</strong>: Puede estar centrado en ejemplos que confirman su idea preconcebida mientras ignora otros países de habla hispana como España o Chile, que tienen PIB significativamente más altos.</li><li><strong>Efecto halo</strong>: Audiard puede estar asumiendo que el idioma por sí solo determina el desarrollo económico de un país, sin considerar el papel de otros factores como las políticas gubernamentales, los recursos naturales o el contexto histórico.</li><li><strong>Sobregeneralización</strong>: Su declaración parece sacar conclusiones generales a partir de pocos ejemplos, quizás pasando por alto la diversidad dentro de los países de habla hispana, que varían considerablemente, aunque no tanto como los países francófonos, en términos de rendimiento económico.</li><li><strong>Ilusión de agrupamiento</strong>: Puede estar viendo una conexión entre idioma y pobreza, pero sin reconocer que hay aleatoriedad y sin tener en cuenta que existen países francófonos pobres, como Haití, que desafiarían esta visión simplista.</li></ul><p>Para más detalles sobre cómo realicé este análisis y las herramientas que utilicé, consulta el <a href="https://github.com/felipevalencla/spanish-language-poor/blob/main/README.md#jacques-audiards-comment-on-spanish-as-a-language-of-the-poor">informe completo</a> en mi GitHub. Este proyecto no solo proporciona una refutación basada en datos a la declaración de Audiard, sino que también explora el panorama económico de estos grupos lingüísticos.</p><p>¡No dudes en echar un vistazo, contribuir o sugerir mejoras! ¡Continuemos la conversación!</p><p><em>Pd: También me interesaba probar la afirmación sobre el español como idioma de los migrantes, pero eso podría revisarse en el futuro.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2271093de0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Truth Behind Audiard’s “Spanish as the Language of the Poor” Claim]]></title>
            <link>https://medium.com/@felipevalencla/the-truth-behind-audiards-spanish-as-the-language-of-the-poor-claim-9581fe28b195?source=rss-790adc816552------2</link>
            <guid isPermaLink="false">https://medium.com/p/9581fe28b195</guid>
            <category><![CDATA[emilia-perez]]></category>
            <category><![CDATA[language]]></category>
            <category><![CDATA[jacques-audiard]]></category>
            <category><![CDATA[poverty]]></category>
            <category><![CDATA[trending-topic]]></category>
            <dc:creator><![CDATA[Felipe Valencia-Clavijo]]></dc:creator>
            <pubDate>Tue, 04 Feb 2025 23:10:12 GMT</pubDate>
            <atom:updated>2025-02-04T23:10:12.656Z</atom:updated>
            <content:encoded><![CDATA[<p>In a comment, French director Jacques Audiard claimed that <em>“Spanish is a language of modest countries, of developing countries, of the poor and migrants.”</em> This statement ignited widespread debate, with many highlighting its bias — particularly given that several of the world’s poorest nations, such as Haiti, are French-speaking.</p><p>Curious to understand whether there’s any truth to Audiard’s claim and the rebuttal claims of the public about French-speaking countries also being framed in that way, I decided to explore the numbers. By analysing economic data on GDP per capita over time using Gapminder’s data, I compared French-speaking and Spanish-speaking countries to see if there was any significant disparity in their economic performance.</p><p>The findings? The data is clear: <strong>French-speaking countries, on average, have a lower GDP per capita than Spanish-speaking ones.</strong> The results were robust, with statistical tests revealing a strong significance <em>(p &lt; 0.01)</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6eCw1eV_IaRCPzwsoTNmVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Eq85UWlvWYJGLvsnHf03A.png" /></figure><p>Audiard’s statement reflects a limited view, <strong>likely influenced by cognitive biases that affect how we perceive and judge others.</strong> Here are some of the biases that may explain his misunderstanding:</p><ul><li><strong>Availability bias</strong>: Audiard may be associating Spanish with poverty due to his possible exposure to certain Spanish-speaking vulnerable communities, which could lead to this distorted view.</li><li><strong>Confirmation bias</strong>: He might be focusing on examples that confirm his preconception while ignoring other Spanish-speaking countries like Spain or Chile, which have significantly higher GDPs.</li><li><strong>Halo effect</strong>: Audiard may be assuming that language alone determines a country’s economic development, without considering the role of other factors such as government policies, natural resources, or historical context.</li><li><strong>Overgeneralization</strong>: His statement seems to draw broad conclusions from just a few examples, perhaps overlooking the diversity within Spanish-speaking countries, which range greatly, although not as greatly as the French-speaking ones, in terms of economic performance.</li><li><strong>Clustering illusion</strong>: He might be seeing a connection between language and poverty, but failing to recognise that there is randomness while ignoring that there are poor Francophone countries, like Haiti, that would challenge this simplistic view.</li></ul><p>For more details on how I conducted this analysis and the tools I used, check out the <a href="https://github.com/felipevalencla/spanish-language-poor/blob/main/README.md#jacques-audiards-comment-on-spanish-as-a-language-of-the-poor">full report</a> on my GitHub. This project not only provides a data-driven rebuttal to Audiard’s statement but also explores the economic landscape of these language groups.</p><p>Feel free to take a look, contribute, or suggest improvements. Let’s continue the conversation!</p><p><em>Pd: I was also interested on testing the claim about Spanish being a language of migrants, but that could be reviewed in the future.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9581fe28b195" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to determine the best combination of hyperparameters for the k-nearest neighbors (KNN) in…]]></title>
            <link>https://medium.com/dataplicada/how-to-determine-the-best-combination-of-hyperparameters-for-the-k-nearest-neighbors-knn-in-18a834eda60b?source=rss-790adc816552------2</link>
            <guid isPermaLink="false">https://medium.com/p/18a834eda60b</guid>
            <category><![CDATA[model-optimization]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[statistical-modeling]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[hyperparameter-tuning]]></category>
            <dc:creator><![CDATA[Felipe Valencia-Clavijo]]></dc:creator>
            <pubDate>Sat, 13 Apr 2024 17:50:35 GMT</pubDate>
            <atom:updated>2024-04-13T17:50:35.226Z</atom:updated>
            <content:encoded><![CDATA[<h3>A practical guide on how to determine the best combination of hyperparameters for the k-nearest neighbors (KNN) classification algorithm in Python</h3><h3>This is Part 1 of “Determining Hyperparameters for KNN classification algorithms and its implications for data-driven organizations and the Environment”</h3><p>This full article will be divided into three parts/posts:</p><ol><li><em>How to determine the best combination of hyperparameters for k-nearest neighbors (KNN) classification algorithm in Python</em>— <strong>Technical but practical hands-on explanation and code for data scientists and ML engineers.</strong></li><li><em>The potential of KNN algorithms in real-world organizations </em>— <strong>A discussion with 1) real-world examples of applications of KNN from the world’s biggest corporations solving complex issues and 2) examples and scenarios of how small and medium-sized enterprises can benefit from KNN classification. This post will be especially useful for researchers, executives, founders, entrepreneurs, and business owners who want to implement data science and ML in their projects and organizations.</strong></li><li><em>Cost implications for organizations and the environmental impact of implementing KNN algorithms</em> — <strong>An analysis of the monetary costs associated with the implementation and the choice of hyperparameters of KNN and a discussion on the environmental impact that comes from the implementation of KNN and other machine learning models. This article is relevant for data engineers, data scientists, ML engineers, executives, stakeholders, economists interested in environmental economics and climate change economics, and people interested in sustainability and energy consumption from the tech industry.</strong></li></ol><p>Let’s start with part 1: <em>A practical guide on how to determine the best combination of hyperparameters for the k-nearest neighbors (KNN) classification algorithm</em></p><p>It is important to first remember what is KNN and what it does. According to IBM:</p><blockquote>“…is a non-parametric, supervised learning classifier, which uses proximity to make classifications or predictions about the grouping of an individual data point.” ¹</blockquote><p>I’m not going to explain how the KNN works in this article since it’s not the purpose of it, but if you want to understand it in more detail, I invite you to read articles and documentation about it. Now, let’s dive into understanding and finding the best combination of hyperparameters for KNN classification.</p><p>First, we import the libraries we are going to be using in Python:</p><pre>import pandas as pd<br>import numpy as np<br>pd.plotting.register_matplotlib_converters()<br>import matplotlib.pyplot as plt<br>%matplotlib inline<br>import seaborn as sns<br>import time</pre><p>We are going to be using the famous <a href="https://en.wikipedia.org/wiki/Iris_flower_data_set">Iris dataset</a>. We load the CSV data available from the web:</p><pre>iris_data = pd.read_csv(&quot;https://gist.github.com/netj/8836201/raw/6f9306ad21398ea43cba4f7d537619d0e07d5ae3/iris.csv&quot;)<br><br># Generate a scatterplot to preview part of the dataset<br>sns.scatterplot(x= &#39;sepal.length&#39;, y = &quot;petal.length&quot;, hue = &quot;variety&quot;, data=iris_data)</pre><figure><img alt="Scatterplot showing that we have 150 observations, 50 for each variety of iris (Setosa, Versicolor, and Virginica)" src="https://cdn-images-1.medium.com/max/555/1*p680vwy_6ru6zluzlKQwHw.png" /></figure><p>We determine the outcome <em>y</em> (what we want our model to classify) in this case, we want our model to classify the category <strong>variety</strong>. Then we determine the features <em>X</em> (the variables that will help us classify), in this case, the <strong>sepal length and width</strong> and the <strong>petal length and width</strong>.</p><pre>#Designate the outcome as y<br>y = iris_data.variety<br><br>#Designate the features to become X<br>iris_features=[&#39;sepal.length&#39;, &#39;sepal.width&#39;,&#39;petal.length&#39;,&#39;petal.width&#39;]<br>X= iris_data[iris_features]</pre><p>Then we create the train, validation, and test datasets. Notice that we use <strong>stratify=y</strong> to make sure that the sampling maintains the same proportion of class labels (variety of species). We are using an 80/20 proportion distribution for the train and test datasets and another 80/20 for the training and validation datasets without the test data.</p><pre>from sklearn.model_selection import train_test_split<br><br># With stratification to balance the output y<br>X_train, X_test, y_train, y_test= train_test_split (X, y, test_size=0.2,random_state=1,stratify=y)<br>X_train, X_val, y_train, y_val= train_test_split (X_train, y_train, test_size=0.2,random_state=1,stratify=y_train)</pre><p>Once the datasets are ready, I can fit the KNN classification model and test it. This is where we ask <em>what hyperparameters I should input to get a proper model? </em>We know that KNN takes several hyperparameters. I decided to focus only on the following ones: <strong>n_neighbors</strong>, <strong>weights</strong>, <strong>algorithms</strong>, and <strong>p</strong>. Again, I’m not going to focus on explaining what each of them does to the fitting of the model. My goal is to help you determine which combination is the best. If you want to understand them more fully, read the <a href="https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html">documentation</a>.</p><h4>Simulation Approach</h4><p>A way to discover the best hyperparameters is through <strong>simulations</strong>. That’s what I want to focus your attention on right now. (I’ll go through another powerful way later in the post.)</p><p>To illustrate how a simulation can help you, I decided to focus only on the <strong>n_neighbors</strong> hyperparameter, which is the most important to the model and where it gets its name from.</p><p>We are going to generate an iterative <em>for loop</em> to run the model several times. We will store the accuracy obtained for each iteration in a list. The KNN classification model will be using the training dataset; however, with a different <strong>number of neighbors (<em>k</em>)</strong>, which is going to be changing in each iteration.</p><pre># Import necessary libraries<br>from sklearn.neighbors import KNeighborsClassifier<br>from sklearn.metrics import accuracy_score<br><br># Lists to store the results of the iterations<br>n_neighbors = []<br>accuracies = []<br><br><br># Simulate for number of neighbors 1 to 20<br>for  k in range(1, 21): # 21 is used because the range is non-inclusive of the last one<br>    # Build classifier<br>    clf_knn = KNeighborsClassifier(n_neighbors=k, weights=&#39;uniform&#39;)<br>          <br>    # Fit the parameterised model to the cross-validated data<br>    clf_knn.fit(X_train, y_train)<br>        <br>    # Obtain predictions on the cross-validation (CV) test set<br>    y_hat_cv = clf_knn.predict(X_val)<br><br>    # Append the neighbors to the list of all of them<br>    n_neighbors.append(k)<br>    <br>    # Append the accuracies to the list of all of them<br>    accuracies.append(accuracy_score(y_val, y_hat_cv))</pre><p>Having done so, we can convert the <strong>n_neighbors</strong> and <strong>accuracies</strong> lists into a dictionary to join them and then into a dataframe for easily visualizing the data obtained from our simulation. With a little bit of coding, we can get the best accuracy score.</p><pre># Generate a dictionary of the lists <br>dict = {&#39;n_neighbor&#39;: n_neighbors, &#39;accuracy&#39;: accuracies}<br><br># Turn the dictionary into a dataframe<br>df = pd.DataFrame(dict)<br><br># Get the best parameter as the index of the argmax in the accuracies list <br>best_parameter = np.argmax(accuracies) + 1 # argmax returns the indices of the maximum values along an axis<br>                                           # (+1 to account for indexing starting at 0)<br><br># Get the best accuracy using the best parameter index <br>best_accuracy = df.accuracy.loc[best_parameter-1]<br><br>print(&quot;Best accuracy is:&quot;, round(df.accuracy.loc[best_parameter-1],3))<br><br># Generate a dataframe only of the best accuracy scores<br>df_best_accuracies = df.query(&#39;accuracy == @best_accuracy&#39;)<br><br>print(&quot;From a total of&quot;, len(df), &quot;combinations, only&quot;, len(df_best_accuracies), &quot;combinations got the best accuracy.&quot;)</pre><pre>Best accuracy is: 0.917<br>From a total of 20 combinations, only 12 combinations got the best accuracy.</pre><p>According to our simulation, the best accuracy was <strong>91.7%</strong>. Let’s plot the entire results of the simulation to see the scores at all numbers of neighbors.</p><pre># Create a lineplot to see the accuracy variation as number of neighbors increase<br>sns.lineplot(data=df, x=&quot;n_neighbor&quot;, y=&quot;accuracy&quot;)<br>plt.xticks(np.arange(0, len(n_neighbors)+1, step=1)) # use the lenght of the list of n_neighbors to get the number of xticks<br><br># Create circles to automatically highlight the best accuracies<br>plt.scatter(df_best_accuracies.n_neighbor, df_best_accuracies.accuracy, s=60, edgecolors=&#39;r&#39;, facecolors=&#39;none&#39;)<br>plt.title(&quot;Accuracy at different number of neighbors&quot;)</pre><figure><img alt="A plot showing the different accuracy scores based on the number of neighbors determined in the parameters" src="https://cdn-images-1.medium.com/max/576/1*vsO9B8nFQ-JNyGncsGpCNA.png" /></figure><p>We can see that effectively 12 out of the 20 options got the biggest accuracies. (3, 4, 9 to 17, and 19 got 91.7%). What do we make about those inconclusive results? Well, it’s not an easy answer but we can find in the literature that a potential rule of thumb is to use the square root of the number of data points <em>k = √n. </em>Following this rule with our dataset we got that k = √150 = 12.25, which can be seen when rounded in our visualization that 12 yields an accuracy of 91.7%.</p><p>Although the use of <em>k = √n</em> has some evidence, it has also been proven not useful for other types of datasets. Researchers did some experiments to test this rule of thumb, but they found that using k = √n as a rule of thumb is not a good choice for the KNN classifier they were working on.²</p><blockquote>“Having run the simulation immediately reduces the plethora of choices and your stress”</blockquote><p>Certainly, there’s not a clear answer, but having run the simulation immediately reduces the plethora of choices and your stress — something good for your anxiety when making choices a behavioural scientist/economist will say.</p><p>Additionally, we can see why is key to always test our models. Also strengthens the fact that when these models are implemented with new raw data they must be revised and if needed retrained. Perhaps a certain <em>k</em> obtained using the rule of thumb of <em>k = √n </em>seems to perform ok with our test data but with new data, it might not, therefore a different <em>k</em> we chose not to use might be better.</p><p>Despite all of the uncertainty that remains, <strong>something that we know for sure is that too few or too many neighbors are problematic</strong>.³ The reason why too few are problematic has something to do with <a href="https://medium.com/@sachinsoni600517/k-nearest-neighbours-introduction-to-machine-learning-algorithms-9dbc9d9fb3b2#:~:text=To%20avoid%20overfitting%20and%20underfitting%20in%20KNN%2C%20it%20is%20important,dataset%20and%20problem%20at%20hand.">overfitting the model</a>. The reason why too many is also problematic can be explained by <a href="https://medium.com/@sachinsoni600517/k-nearest-neighbours-introduction-to-machine-learning-algorithms-9dbc9d9fb3b2#:~:text=To%20avoid%20overfitting%20and%20underfitting%20in%20KNN%2C%20it%20is%20important,dataset%20and%20problem%20at%20hand.">underfitting the model</a>, but there’s a bigger elephant in the room than just that. More will be discussed in part 3.</p><h4>An example of a more robust simulation</h4><p>Having reviewed how the simulation works for finding the best combination of hyperparameters using only the number of neighbors (<em>k</em>). Let’s perform a more complex simulation. This time we will combine the following hyperparameters we decided to focus on earlier: <strong>n_neighbors</strong>, <strong>weights</strong>, <strong>algorithms</strong>, and <strong>p</strong>.</p><p>The simulation uses again <em>for loops</em>, but to test all possible combinations we need to create <em>four nested for loops</em>. with the following notations:</p><ul><li><em>j</em> is for each of the three available algorithms (ball_tree, kd_tree, and brute).</li><li><em>k</em> is for each number of neighbors, in this case, we will try from 1 to 20.</li><li><em>w</em> is for each of the available weights (uniform and distance).</li><li><em>p</em> is for each power hyperparameter for the Minkowski metric. (When p = 1 is for Manhattan distance, and p = 2 is for Euclidean distance).</li></ul><p>Having 3 algorithms, 20 neighbors, 2 weights, and 2 power hyperparameters, we have a total of 240 possible combinations of hyperparameters.</p><p>Similar to the previous example, we will store the accuracy obtained for each iteration in a list. The KNN classification model will be using the training dataset; however, with a different <strong>number of neighbors (<em>k</em>)</strong>, <strong>algorithms (<em>j</em>)</strong>, <strong>weights (<em>w</em>)</strong>, and <strong>power hyperparameters (<em>p</em>)</strong>, which are going to be changing in each iteration.</p><pre># Lists to store the results of the iterations<br>n_neighbors = []<br>weights = []<br>algorithms = []<br>ps = []<br>accuracies = []<br><br><br># Simulate for number of neighbors 1 to 20 with each of the weights, algorithms, and Ps <br>for j in [&#39;ball_tree&#39;,&#39;kd_tree&#39;,&#39;brute&#39;]:<br>    for  k in range(1, 21): # 21 is used because the range it&#39;s non-inclusive of the last one<br>        for p in [1, 2]:<br>            for w in [&#39;uniform&#39;, &#39;distance&#39;]:<br>                # Build classifier.<br>                clf_knn = KNeighborsClassifier(n_neighbors=k, weights=w, algorithm=j, p=p)<br><br>                # Fit the parameterised model to the cross-validated data<br>                clf_knn.fit(X_train, y_train)<br><br>                # Obtain predictions on the cross-validation (CV) test set<br>                y_hat_cv = clf_knn.predict(X_val)<br><br>                # Append the neighbors to the list of all of them.<br>                n_neighbors.append(k)<br><br>                # Append the weights to the list of all of them.<br>                weights.append(w)<br><br>                # Append the algorithms to the list of all of them.<br>                algorithms.append(j)<br>                <br>                # Append the algorithms to the list of all of them.<br>                ps.append(p)<br><br>                # Append the accuracies to the list of all of them.<br>                accuracies.append(accuracy_score(y_val, y_hat_cv))<br>                #print(&#39;Neighbors:&#39;,k, &#39;\ Accuracy:&#39;,round(accuracies[k-1],2)) # (k-1 to account for indexing starting at 0)</pre><p>Having done so, we can convert the <strong>n_neighbors, weights, algorithms, ps, </strong>and <strong>accuracies</strong> lists into a dictionary to join them and then into a dataframe for easily visualizing the data obtained from our simulation. With a bit of coding, we can get the best accuracy score.</p><pre># Generate a dictionary of the lists<br>dict = {&#39;n_neighbor&#39;: n_neighbors, &#39;weight&#39;: weights, &#39;algorithm&#39;: algorithms, &#39;p&#39;:ps, &#39;accuracy&#39;: accuracies}<br><br># Turn the dictionary into a dataframe<br>df = pd.DataFrame(dict)<br><br># Get the best parameter as the index of the argmax in the accuracies list <br>best_parameter = np.argmax(accuracies) # argmax returns the indices of the maximum values along an axis<br><br># Get the best accuracy using the best parameter index <br>best_accuracy = df.accuracy.loc[best_parameter]<br><br>print(&quot;Best accuracy is:&quot;, round(df.accuracy.loc[best_parameter],3))<br><br># Generate a dataframe only of the best accuracy scores<br>df_best_accuracies = df.query(&#39;accuracy == @best_accuracy&#39;)<br><br>print(&quot;From a total of&quot;, len(df), &quot;combinations, only&quot;, len(df_best_accuracies), &quot;combinations got the best accuracy.&quot;)</pre><pre>Best accuracy is: 0.958<br>From a total of 240 combinations, only 21 combinations got the best accuracy.</pre><p>According to our simulation, the best accuracy was <strong>95.8%</strong>. Also, our options for combinations of hyperparameters have been significantly reduced from 240 combinations to 21 possible best combinations. That’s quite convenient!</p><figure><img alt="Swarmplots showing the different accuracies at all number of neighbors for each weight, algorithm, and power parameters." src="https://cdn-images-1.medium.com/max/1024/1*I9EKKkVLUJhxKH5NmbLniQ.png" /><figcaption>All accuracies at all numbers of neighbors.</figcaption></figure><p>By filtering the combinations with the highest accuracy we got the following table:</p><figure><img alt="A table showing the best parameter combinations that yield the highest accuracy." src="https://cdn-images-1.medium.com/max/396/1*TdaMYZO2UQYS6udXw6pK4Q.png" /><figcaption>Table of all the combinations of hyperparameters that yield the highest accuracy</figcaption></figure><p>We have reduced our options to choose and test the best model to only 21! To make an educated guess about which of the 21 combinations is the best, we can follow the rule of thumb of <em>k = √n. (</em>k = √150 = 12.25 rounded is equal to 12). We can see that 3 options fit that rule. Now our decision-making process is easier and less prone to anxiety.</p><h4>A powerful tool: GridSearchCV</h4><p>GridSearchCV exhaustively simulates the different combinations of hyperparameters you established and gives you the best option using some internal <a href="https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html">criteria</a>.</p><p>Let’s perform the same simulation with GridSearchCV. Again we will combine the following hyperparameters we decided to focus on earlier: <strong>n_neighbors</strong>, <strong>weights</strong>, <strong>algorithms</strong>, and <strong>p</strong>.</p><p>As a reminder, having 3 algorithms, 20 neighbors, 2 weights, and 2 power hyperparameters, we end up with 240 possible combinations of hyperparameters.</p><p>The KNN classification model will use the training dataset as we did with our previous simulation.</p><pre># Import necessary libraries<br>from sklearn.neighbors import KNeighborsClassifier<br><br># Create a basic 2NN classifier<br>kNN = KNeighborsClassifier(n_neighbors=2)<br><br># Setup the GridSearchCV<br>from sklearn.model_selection import GridSearchCV<br><br># Make a dictionary with the parameters I want to set,<br># and the range of values I want to cross-validate over<br>parameters = {<br>    &quot;n_neighbors&quot; : [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],<br>    &quot;weights&quot;: [&#39;uniform&#39;,&#39;distance&#39;],<br>    &quot;algorithm&quot;: [&#39;ball_tree&#39;,&#39;kd_tree&#39;,&#39;brute&#39;],<br>    &quot;p&quot;:[1,2] <br>}<br><br># Build classifier<br>clf = GridSearchCV(kNN,param_grid=parameters)<br># Fit the parameterised model to the cross-validated data<br>clf.fit(X_train, y_train)<br><br># Print the best parameter combination according to GridSearchCV:<br>print(clf.best_params_)<br><br># Obtain predictions on the cross-validation (CV) test set<br>y_hat = clf.predict(X_val)<br><br>accuracy = accuracy_score(y_val, y_hat)<br>print(&quot;Accuracy:&quot;,round(accuracy,3))</pre><pre>{&#39;algorithm&#39;: &#39;ball_tree&#39;, &#39;n_neighbors&#39;: 5, &#39;p&#39;: 2, &#39;weights&#39;: &#39;uniform&#39;}<br>Accuracy: 0.875</pre><p>According to GridSearchCV, the accuracy was <strong>87.5%</strong> and the best combination of hyperparameters was:</p><ul><li><strong>ball_tree</strong> as the algorithm</li><li><strong>5</strong> neighbors</li><li>A power hyperparameter for the Minkowski metric of <strong>p = 2</strong> (Euclidean distance)</li><li>A<strong> uniform</strong> weight</li></ul><blockquote>“…our decision-making process is easy and without anxiety”</blockquote><p>In this case, we don&#39;t have to worry about choosing since GridSearchCV chose it for us. So, our decision-making process is easy and without anxiety. Nevertheless, if we compare the accuracy results of <em>the simulation we built</em> and of <em>GridSearchCV</em> we notice a difference in outcome. Respectively, <strong>95.8% </strong>and<strong> 87.5%. </strong>One potential explanation for the outcomes being different is that GridSearchCV performs a series of additional tests and criteria to score the best combination of hyperparameters.</p><h4>Testing both models</h4><p>At this point, we trained both models with the same training dataset, we obtained the best combination of hyperparameters using the validation dataset. Now that we have both of our selected models, we can perform a test with the test dataset to check the performance of <em>one of the models we chose through the iterative simulation we built</em> and of <em>the model selected by GridSearchCV</em>.</p><p>Testing<em> one of the models we chose through the iterative simulation we built:</em></p><pre># Build classifier with the parameters determined by my iterative simulation<br>clf_knn = KNeighborsClassifier(n_neighbors=12, weights=&#39;distance&#39;, algorithm=&#39;ball_tree&#39;, p=1)<br><br># Fit the parameterised model to the test data<br>clf_knn.fit(X_train, y_train)<br><br># Obtain predictions on the test set<br>y_hat_cv = clf_knn.predict(X_test)<br><br># Print accuracy<br>print(&quot;Accuracy:&quot;, round(accuracy_score(y_test, y_hat_cv),3))</pre><pre>Accuracy: 0.967</pre><p>Testing<em> the model selected by GridSearchCV:</em></p><pre># Build classifier with the parameters determined by GridSearchCV<br>clf_knn = KNeighborsClassifier(n_neighbors=5, weights=&#39;uniform&#39;, algorithm=&#39;ball_tree&#39;, p=2)<br><br># Fit the parameterised model to the test data<br>clf_knn.fit(X_train, y_train)<br><br># Obtain predictions on the test set<br>y_hat_cv = clf_knn.predict(X_test)<br><br># Print accuracy<br>print(&quot;Accuracy:&quot;, round(accuracy_score(y_test, y_hat_cv),3))</pre><pre>Accuracy: 0.967</pre><p>We can see that both models with their specified combination of hyperparameters gave us an accuracy of 96.7%. In this case, both models yield a great performance, so both are good options to implement. But as always, in the real world with new raw data, the performance may differ. That’s why it’s important to look back to the modelling process when needed and make decisions based on real model feedback and performance to improve it.</p><p>Thank you for reading this post. Stay tuned for Part 2: <em>The potential of KNN algorithms in real-world organizations </em>— <strong>A discussion with 1) real-world examples of applications of KNN from the world’s biggest corporations solving complex issues and 2) examples and scenarios of how small and medium-sized enterprises can benefit from KNN classification. This post will be especially useful for researchers, executives, founders, entrepreneurs, and business owners who want to implement data science and ML in their projects and organizations.</strong></p><blockquote>To learn more about me and discover additional insights <strong>follow me on </strong><a href="https://www.linkedin.com/in/felipevalenciaclavijo/"><strong>Linkedin</strong></a>. You can also explore my Medium articles by <strong>visiting my </strong><a href="https://medium.com/@felipeval"><strong>Medium page</strong></a><strong>. </strong>If you are interested in implementing Data Science and Machine Learning in your organization<strong> visit </strong><a href="https://dataplicada.com/">https://dataplicada.com/</a>.</blockquote><p>References:</p><p>[1] <em>What is the K-nearest neighbors algorithm?</em>. IBM. (n.d.). <a href="https://www.ibm.com/topics/knn">https://www.ibm.com/topics/knn</a></p><p>[2] Hassanat, A. B., Abbadi, M. A., Altarawneh, G. A., &amp; Alhasanat, A. A. (2014). Solving the problem of the K parameter in the KNN classifier using an ensemble learning approach. <em>arXiv preprint arXiv:1409.0919</em>.</p><p>[3] Gupta, S. (2023, June 26). <em>Knn Machine Learning Algorithm explained</em>. Springboard Blog. <a href="https://www.springboard.com/blog/data-science/knn-algorithm/">https://www.springboard.com/blog/data-science/knn-algorithm/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18a834eda60b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dataplicada/how-to-determine-the-best-combination-of-hyperparameters-for-the-k-nearest-neighbors-knn-in-18a834eda60b">How to determine the best combination of hyperparameters for the k-nearest neighbors (KNN) in…</a> was originally published in <a href="https://medium.com/dataplicada">Dataplicada Insights</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>