<?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 Nura Kawa on Medium]]></title>
        <description><![CDATA[Stories by Nura Kawa on Medium]]></description>
        <link>https://medium.com/@nurakawa?source=rss-b627ffbd638e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lFLCWX392dMS-kWwLUBHDQ.jpeg</url>
            <title>Stories by Nura Kawa on Medium</title>
            <link>https://medium.com/@nurakawa?source=rss-b627ffbd638e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 12:34:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nurakawa/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[Machine Learning Experiments Done Right]]></title>
            <link>https://medium.com/data-science/machine-learning-experiments-done-right-6ed04f5e959b?source=rss-b627ffbd638e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ed04f5e959b</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[experimentation]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[tips-and-tricks]]></category>
            <dc:creator><![CDATA[Nura Kawa]]></dc:creator>
            <pubDate>Mon, 02 Dec 2024 18:23:58 GMT</pubDate>
            <atom:updated>2024-12-02T18:23:58.610Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>A detailed guideline for designing machine learning experiments that produce reliable, reproducible results.</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7hM8dogh6AZWedF2" /><figcaption>Photo by <a href="https://unsplash.com/@vedranafilipovic?utm_source=medium&amp;utm_medium=referral">Vedrana Filipović</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Machine learning (ML) practitioners run experiments to compare the effectiveness of methods for both specific applications and for general types of problems. The validity of experimental results hinges on how practitioners design, run, and analyze their experiments. Unfortunately, many ML papers lack valid results. Recent studies [<a href="https://www.jmlr.org/papers/volume22/20-303/20-303.pdf">5</a>] [<a href="https://arxiv.org/pdf/1909.06674">6</a>] reveal a lack of reproducibility in published experiments, attributing this to practices such as:</p><ul><li><em>Data contamination</em>: engineering training datasets to include data that is semantically similar to, or directly from, the test dataset</li><li><em>Cherrypicking</em>: selectively choosing an experimental setup or results that favorably present a method</li><li><em>Misreporting</em>: including “the improper use of statistics to analyze results, such as claiming significance without proper statistical testing or using the wrong statistic test [<a href="https://www.jmlr.org/papers/volume22/20-303/20-303.pdf">6</a>]</li></ul><p>Such practices are not necessarily done intentionally — practitioners may face pressure to produce quick results or lack adequate resources. However, consistently using poor experimental practices inevitably leads to costly outcomes. So, how should we conduct Machine Learning experiments that achieve reproducible and reliable results? <strong>In this post, we present a guideline for designing and executing rigorous Machine Learning experiments</strong>.</p><h3>Experiments: factors and response functions</h3><p>An experiment involves a system with an input, a process, and an output, visualized in the diagram below. Consider a garden as a simple example: bulbs are the input, germination is the process, and flowers are the output. In an ML system, data is input into a learning function, which outputs predictions.</p><p>A practitioner aims to maximize some <em>response function</em> of the output — in our garden example, this could be the number of blooming flowers, while in an ML system, this is usually model accuracy. This response function depends on both controllable and uncontrollable factors. A gardener can control soil quality and daily watering but cannot control the weather. An ML practitioner can control most parameters in a ML system, such as the training procedure, parameters and pre-processing steps, while randomness comes from data selection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*N-Ghl7UA_t_Zj_K4EX-ysA.png" /><figcaption><em>Diagram of an experiment, based on [</em><a href="https://www.youtube.com/watch?v=1I4Hudel5mk"><em>2</em></a><em>]</em></figcaption></figure><p>The goal of an experiment is to find the best configuration of controllable factors that maximizes the response function while minimizing the impact of uncontrollable factors. <strong>A well-designed experiment needs two key elements: a systematic way to test different combinations of controllable factors, and a method to account for randomness from uncontrollable factors.</strong></p><p>Building on these principles, a clear and organized framework is crucial for effectively designing and conducting experiments. Below, we present a checklist that guides a practitioner through the planning and execution of an ML experiment.</p><h3>A Machine Learning Experiment Checklist</h3><p><em>To plan and perform a rigorous ML experiment:</em></p><ol><li>State the <em>objective</em> of your experiment</li><li>Select the <em>response function</em>, or what you want to measure</li><li>Decide what factors vary, and what remains the same</li><li>Describe one <em>run</em> of the experiment, which should define:<br>(a) a single configuration of the experiment<br>(b) the datasets used</li><li>Choose an <em>experimental design</em>, which should define:<br>(a) how we explore the factor space and<br>(b) how we repeat our measurements (cross validation)</li><li>Perform the experiment</li><li>Analyze the data</li><li>Draw conclusions and recommendations</li></ol><h4>1. State the objective of the experiment</h4><p>The objective should state clearly why is the experiment to be performed. It is also important to <strong>specify a meaningful effect size.</strong> For example, if the goal of an experiment is “to determine the if using a data augmentation technique improves my model’s accuracy”, then we must add, “a significant improvement is greater than or equal to 5%.”</p><h4>2. Select the response function, or what you want to measure</h4><p>The response function of a Machine Learning experiment is typically an accuracy metric relative to the task of the learning function, such as classification accuracy, mean average precision, or mean squared error. It could also be a measure of interpretability, robustness or complexity — so long as the metric is be well-defined.</p><h4>3. Decide what factors vary, and what remains the same</h4><p>A machine learning system has several controllable factors, such as model design, data pre-processing, training strategy, and feature selection. In this step, we decide what factors remain static, and what can vary across runs. For example, if the objective is “to determine the if using a data augmentation technique improves my model’s accuracy”, we could choose to vary the data augmentation strategies and their parameters, but keep the model the same across all runs.</p><h4>4. Describe one run of the experiment</h4><p>A <em>run</em> is a single instance of the experiment, where a process is applied to a single configuration of factors. In our example experiment with the aim “to determine the if using a data augmentation technique improves my model’s accuracy”, a single run would be: “to train a model on a training dataset using one data augmentation technique and measure its accuracy on a held-out test set.”</p><p>In this step, we also select the data for our experiment. When choosing datasets, we must consider whether our experiment a domain-specific application or for generic use. A domain-specific experiment typically requires a single dataset that is representative of the domain, while experiments that aim to show a generic result should evaluate methods across multiple datasets with diverse data types [<a href="https://towardsdatascience.com/a-quick-guide-to-designing-rigorous-machine-learning-experiments-21b19f067703">1</a>].</p><p>In both cases, we must define specifically the training, validation and testing datasets. If we are splitting one dataset, we should record the data splits. This is an essential step in avoiding accidental contamination!</p><h4>5. Choose an experimental design</h4><p>The experimental design is is the collection of runs that we will perform. An experiment design describes:</p><ul><li>What factors and <em>levels</em> (categories or values of a factor) will be studied</li><li>A randomization scheme (cross validation)</li></ul><p>If we are running an experiment to test the impact of training dataset size on the resulting model’s robustness, which range of sizes will we test, and how granular should we get? When varying multiple factors, does it make sense to test all possible combinations of all factor/level configurations? If we plan to perform statistical tests, it could be helpful to follow a specific experiment design, such as a factorial design or randomized block design (see [<a href="https://elearning.unite.it/pluginfile.php/221606/mod_resource/content/1/BookDOEwithR.pdf">3</a>] for more information).</p><p>Cross validation is essential for ML experiments, as this reduces the variance of your results which come from the choice of dataset split. To determine the number of cross-validation samples needed, we return to our objective statement in Step 1. If we plan to perform a statistical analysis, we need to ensure that we generate enough data for our specific statistical test.</p><p>A final part of this step is to think about <strong>resource constraints</strong>. How much time and compute does one run take? Do we have enough resources to run this experiment as we designed it? Perhaps the design must be altered to meet resource constraints.</p><h4>6. Perform the experiment</h4><p>To ensure that the experiment runs smoothly, It is important to have a rigorous system in place to organize data, track experiment runs, and analyze resource allocation. Several open-source tools are available for this purpose (see <a href="https://github.com/awesome-mlops/awesome-ml-experiment-management">awesome-ml-experiment-management</a>).</p><h4>7. Analyze the data</h4><p>Depending on the objective and the domain of the experiment, it could suffice to look at cross-validation averages (and error bars!) of the results. However, the best way to validate results is through statistical hypothesis testing,<strong> </strong>which rigorously shows that the probability of obtaining your results given the data is not due to chance. Statistical testing is necessary if the objective of the experiment is to show a cause-and-effect relationship.</p><h4>8. Draw conclusions</h4><p>Depending on the analysis in the previous step, we can now state the conclusions we draw from our experiment. Can we make any claims from our results, or do we need to see more data? Solid conclusions are backed by the resulting data and are reproducible. Any practitioner who is unfamiliar with the experiment should be able to run the experiment from start to finish, obtain the same results, and draw from the results the same conclusions.</p><h3>Final Thoughts</h3><p>A Machine Learning experiment has two key factors: a systematic design for testing different combinations of factors, and a cross-validation scheme to control for randomness. Following the ML experiment checklist of this post throughout the planning and execution of an experiment can help a practitioner, or a team of practitioners, ensure that the resulting experiments are reliable and reproducible.</p><p>Thank you for reading! If you found this post useful, please consider following me on <a href="https://medium.com/@jorisguerin">Medium</a>, or checking out my <a href="https://nurakawa.github.io/">website</a>.</p><h3>References</h3><p>[1] Joris Guerin “A Quick Guide to Design Rigorous Machine Learning Experiments.” <em>Towards Data Science. </em><a href="https://towardsdatascience.com/a-quick-guide-to-designing-rigorous-machine-learning-experiments-21b19f067703">Available Online</a>.</p><p>[2] Design &amp; Analysis of Machine Learning Experiments — Machine Learning — Spring 2016 — Professor Kogan. <a href="https://www.youtube.com/watch?v=1I4Hudel5mk">YouTube video</a>.</p><p>[3] Lawson, John. <em>Design and analysis of experiments with R.</em> <a href="https://elearning.unite.it/pluginfile.php/221606/mod_resource/content/1/BookDOEwithR.pdf">Available Online</a>.</p><p>[4] Questionable Practices in Machine Learning. <a href="https://arxiv.org/pdf/2407.12220v1">ArXiv preprint</a>.</p><p>[5] Improving Reproducibility in Machine Learning Research. <em>Journal of Machine Learning Research, </em>2022. <a href="https://www.jmlr.org/papers/volume22/20-303/20-303.pdf">Available Online</a>.</p><p>[6] A Step Toward Quantifying Independently Reproducible Machine Learning Research. <a href="https://arxiv.org/pdf/1909.06674">ArXiv preprint</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ed04f5e959b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/machine-learning-experiments-done-right-6ed04f5e959b">Machine Learning Experiments Done Right</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Explainable AI (XAI) with Class Maps]]></title>
            <link>https://medium.com/data-science/explainable-ai-xai-with-class-maps-d0e137a91d2c?source=rss-b627ffbd638e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0e137a91d2c</guid>
            <category><![CDATA[explainable-ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[editors-pick]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Nura Kawa]]></dc:creator>
            <pubDate>Wed, 02 Feb 2022 15:08:11 GMT</pubDate>
            <atom:updated>2022-02-02T15:08:11.901Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introducing a novel visual tool that explains the results of classification algorithms, with examples in R and Python.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qLP9Ef9DilngawXw" /><figcaption>Photo by <a href="https://unsplash.com/@charlesdeluvio?utm_source=medium&amp;utm_medium=referral">Charles Deluvio</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>The need for model explanations</h3><p>Classification algorithms aim to identify to which groups a set of observations belong. A machine learning practitioner typically builds multiple models and selects a final classifier to be one that optimizes a set of accuracy metrics on a held-out test set. Sometimes, <strong>practitioners and stakeholders want more from the classification model than just predictions. They may wish to know the reasons behind a classifier’s decisions, especially when it is built for high-stakes applications</strong>. For instance, consider a medical setting, where a classifier determines a patient to be at high risk for developing an illness. If medical experts can learn the contributing factors to this prediction, they could use this information to help determine suitable treatments.</p><p>Some models, such as single decision trees, are transparent, meaning that they show the mechanism for how they make decisions. More complex models, however, tend to be the opposite — they are often referred to as “black boxes”, as they provide no explanation for how they arrive at their decisions. Unfortunately, opting for transparent models over black boxes does not always solve the explainability problem. The relationship between a set of observations and its labels is often too complex for a simple model to suffice; transparency can come at the cost of accuracy [1].</p><p>The increasing use of black-box models in high-stakes applications, combined with the need for explanations, has lead to the development of <strong>Explainable AI (XAI)</strong>,<strong> </strong>a set of methods that help humans understand the outputs of machine learning models. Explainability is a crucial part of the responsible development and use of AI.</p><h3>Visualizing the perspective of the classifier</h3><p>When we cannot derive an explanation directly from a classifier, we can use <em>post-hoc interpretations,</em> a category of XAI methods that explain a model’s predictions without necessarily revealing how it works [3]. Visualization is a powerful way to explain complex decisions in a simple, human-friendly manner. Furthermore, visualization tools can be easily placed within a machine learning pipeline, allowing for automatic explanations of training sets, test sets, or special subsets (for example, visualizing a classifier’s performance across sensitive groups).</p><p><a href="https://arxiv.org/abs/2007.14495">Raymaekers et al. (2021)</a> introduces the <strong>class map</strong>, a visual tool that maps the probabilities output from a classifier to the distribution of the observations for which it makes predictions. Class maps show us observations <em>from the perspective of a classifier</em>, shedding light on the relationship between a classifier’s decision rules and the structure of the data. Practitioners can use class maps to determine whether a classification model makes errors only on edge cases, or if it misses observations that humans can easily identify. We can also get an idea if a classifier performs consistently across sub-groups of observations, indicating its level of fairness.</p><p>Essentially, <strong>class maps help us easily determine whether we can trust a model before deploying it</strong>.</p><p>The best way to understand a class map is with a simple example (<em>Note: the code for this and all following examples are available at the end of this post.</em>)</p><h3>Example: Classifying the Iris Dataset</h3><p>Consider the task of classifying the benchmark iris dataset, which contains four attributes of 150 observations of iris flowers, evenly divided into three species: setosa, versicolor and virginica. To get an idea of the structure of the data, we first show a Principal Component Analysis (PCA) view, colored by class label:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*tJy32NBJWdavkV-RhnYPgQ.png" /><figcaption>A Principal Component Analysis (PCA) view of the iris dataset, colored by ground-truth class label. The “setosa” irises appear as a distinct group, while “versicolor” and “virginica” have some overlap, making them harder to classify | Image by author</figcaption></figure><p>Observations from the setosa species exist as a distinct group, while versicolor and virginica flowers have more in common. A classifier will likely have difficulty classifying observations from the latter two classes.</p><p>As the data appears to be linearly separable, we opt to fit a Linear Discriminant Analysis classifier (note: we do not do a train/test split in this example, but fit the classifier to the entire dataset). We obtain a fitted classifier with 98% accuracy. We could stop there, or we could ask: Where does the classifier make mistakes, and why ?</p><p>Let’s look at a <strong>class map</strong> for the observations with ground-truth labels “versicolor” and “virginica”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*wb5d7qwRIsvH_PdNWsQEPA.png" /><figcaption>Class maps of observations with ground-truth labels “versicolor” (left) and “virginica” (right). The class maps show the classifier’s perspective of the data. Each observation is a point, colored by the classifier’s predicted class. The y-axis shows the probability that an observation belongs to an alternative class. The x-axis is farness, a measure of how far an object lies from its class center. Here, the misclassified observations are far from their class, indicating that they are challenging examples to classify | Image by author</figcaption></figure><p>The class map visualizes observations with ground-truth label belonging to a single class as a scatterplot. Each observation is colored by its predicted class. For each observation, the class map reflects the <strong>probability that the observation belongs to an alternative class</strong> (on the y-axis) against a <strong>measure of how far it is from its own class</strong> (on the x-axis). These quantities are called Probability of Alternative Classification (PAC) and farness, respectively, and are derived from the trained classifier. An interested reader can find the mathematical definitions of each quantity in <a href="https://arxiv.org/abs/2007.14495">Raymaekers et al. (2021)</a>.</p><p>Looking horizontally, the class map of observations belonging to class “versicolor” (left) shows that the classifier sees most observations as typical of their class. A few observations are deemed “far” from their class. A roughly similar picture is shown for the virginica flowers, but the distribution of observations of this class is more spread out — there are more observations with high farness. Looking vertically at each class map, we see the conditional probability that each observation belongs to its class, derived from the trained classifier. Most observations are seen as highly likely belonging to their ground-truth class. However, three observations in total are misclassified. Looking at the PCA view of the data, it is not surprising to see that the classifier finds confusion between versicolor and virginica flowers.</p><p>We can also see how the classifier views observations with ground-truth label “setosa”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*awEhsRTbIHIaStlSGIAQ-A.png" /><figcaption>Class map of class “setosa”. The classifier is certain that all observations belong in the same class | Image by author</figcaption></figure><p>Looking vertically, we see that the classifier is strongly certain that all observations of this class belong to their true label. This is true regardless of where an observation lies with respect to its class center.</p><p>While this example is much simpler than a typical classification problem, it shows the idea behind a class map. With this tool, we are able to see how the data are viewed by a specific classifier. We understand that the “setosa” class is easy to classify, while the other two classes provide more challenge. The classifier makes mistakes on observations that are atypical of their own class.</p><p>Both quantities plotted in a class map are derived from a trained classifier, making this method <strong>model-dependent. </strong>Currently, class maps are available for the following classifiers: Discriminant Analysis, K-nearest neighbors, Support Vector Machines, Decision Trees, Random Forest, and Neural networks.</p><p>But what if we want explanations of other classification models ?</p><h3>The <em>localized</em> class map: a model-agnostic class map</h3><p>A second kind of class map is the <strong>localized class map</strong>, a model-agnostic version of the class map, introduced in <a href="https://github.com/nurakawa/localized-classmap/blob/main/msc_thesis_kawa.pdf">Kawa (2021)</a>. The y-axis, which shows the conditional probability than an observation belongs to its ground-truth class, remains unchanged. The x-axis of the localized class map displays <strong><em>localized farness</em>, a measure which uses local qualities of the data to assess where an object lies in the data space</strong>. This shows a picture of how the classifier performs with respect to the local and global structure of the data.</p><p>Localized farness measures how far an observation lies from its class by looking within its local neighborhood. It is based on method presented in <a href="https://link.springer.com/article/10.1007/s10844-015-0368-1">Napierala (2015) </a>. For a <em>k-</em>neighborhood of an observation <em>i</em>, localized farness computes a weighted ratio of neighbors from the same ground-truth class. If <em>i </em>belongs to a neighborhood where nearly all neighbors belong to the same class, it has a low localized farness; essentially, it lives close to its class members. If <em>i </em>lives in a neighborhood where most of its neighbors are from a different class, then it is far from its own class. In the definition (which can be found in <a href="https://nurakawa.github.io/localized-class-map">this blog post</a>), more weight is given to closer neighbors. The user determines the appropriate <em>k</em>, or the size of the neighborhood, with the default set to<em> k=10.</em></p><p>By replacing farness with localized farness, we can make class maps for any classifier (if the data are not numeric, we can use Gower’s distance to find its nearest neighbors). Furthermore, the resulting view of the distribution of the data does not depend on the classifier. So, we can use this version of the class map to get an idea of how difficult the data is to classify, and compare different classifiers on the same data.</p><p>As with the original class map, we explain the localized class map with a benchmark example. More detailed explanations and examples can be found <a href="https://github.com/nurakawa/localized-classmap/blob/main/msc_thesis_kawa.pdf">here</a>.</p><h3>Example: Classifying Handwritten Digits</h3><p>A benchmark problem in machine learning is the <a href="https://en.wikipedia.org/wiki/MNIST_database">classification of the MNIST handwritten digits dataset</a>. We train a Multi-layer Perceptron (MLP) on a training set of 60,000 handwritten digits, obtaining a 96.11% accuracy on a held-out test set of 10,000 digits. To get an idea of the performance of this classifier, we can look to a confusion matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*13TeM1PTewO7ePWR.png" /><figcaption><em>Figure 1: Confusion matrix of a MLP classifier reflecting test-set perforamance by class </em>| Image by author</figcaption></figure><p>Viewing the image horizontally, we can see how the classifier performs for each label in the test set (digits 0–9). For the images with true label “3”, we see that the classifier identifies most images to their true class. However, it incorrectly identifies 12 images to label “5”. Looking at observations having true label “9”, we see the classifier has most confusion between “9” and “4”.</p><p>For some applications, a confusion matrix gives a good enough picture of the classification. However, sometimes we want to know more. For instance,</p><ul><li>For which examples does a classifier make mistakes?</li><li>Does the classifier make errors that humans also make ? Or, does it make mistakes on the relatively easy examples?</li><li>Are some classes more difficult to classify than others ? In other words, do some classes contain many challenging examples and/or contamination?</li></ul><p>As in the first example, we can use a class map to answer these questions from the perspective of the classifier<em>. </em>To get a model-agnostic view, we can plot a <strong>localized class map</strong> for each digit in the test set. Below is the localized class map for observations with ground-truth label “3”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*lQ7sul9N6HtHanF7.png" /><figcaption><em>Localized class map of the test set observations with ground truth label “3”. The classifier performs better for this class than its overall performance. Most observations that are misclassified have a high localized farness, meaning that they live in neighborhoods that are not homogeneous </em>| Image by author</figcaption></figure><p>Like before, each observation is visualized as point, colored by predicted label. The y-axis remains as Probability of Alternative Class (PAC), which reflects how likely the classifier would assign the observations to an alternative class. Here, we see that most observations have PAC = 0; the classifier is quite confident that they belong to their own class. However, quite a few points have a higher PAC value, reflecting the classifier’s uncertainty with their class membership.</p><p>On the x-axis we have <strong>localized farness</strong>, which measures how far an observation lies from its own class (here, we use the default value of <em>k </em>to compute localized farness) with respect to a local neighborhood. Most objects have a relatively low localized farness, meaning that they are typical examples of a digit “3”. Some objects, however, deviate from their class. We have identified three examples in the localized class map and plotted them below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*rTIoPEd7CNM78hqZ.png" /><figcaption><em>Examples of observations with ground truth label “3” that have a high localized farness. They are atypical examples from their class </em>| Image by author</figcaption></figure><p>Viewing from left to right, the first two image have a PAC close to 0 — the classifier is quite sure that they belong to digit “3”, although they look different from the average digit. The last image has a PAC = 1: the classifier is strongly certain that this image is of digit “7”. It is sensible that the classifier believes this; the image is a challenging example for a human to classify.</p><p>We can also plot a localized class map from the same classifier, this time for examples with ground-truth label “9”, this time using <em>k</em>=40 nearest neighbors to compute localized farness:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*4vORR-hAVeTg7sqh.png" /><figcaption><em>Localized class map for test set observations with ground-truth label “9”. The classifier performs poorly even on observations that lie in relatively homogeneous neighborhoods. It has the most confusion between classes “9” and “4” </em>| Image by author</figcaption></figure><p>For this class, the classifier has relatively poorer performance. Indeed, we see quite a few points misclassified to digit “4”. The classifier seems to make mistakes irrespective of an observation’s localized farness. The classifier misses some easy examples, and correctly identifies some challenging examples. This indicates that <strong>the classifier does not make its decisions in line with observations’ local distances</strong>. Had we used, for instance, a k-nearest neighbor classifier, we would find instead a strong correlation between localized farness and PAC.</p><p>As we did previously, we can look at examples of observations with localized farness = 0 (they are typical examples of their class):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*HgISssXAFVhqkS2l.png" /><figcaption><em>Examples of observations with ground truth label “9” that have zero localized farness. They are typical examples from their class </em>| Image by author</figcaption></figure><p>and those with relatively high localized farness, which lie in neighborhoods close to other digits:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*8jABJtNWUI7J-r_n.png" /><figcaption><em>Examples of observations with ground truth label “9” that have high localized farness. They are atypical examples from their class, and most are misclassified </em>| Image by author</figcaption></figure><p>We can see why each example lives in a heterogeneous neighborhood. In the top row, the examples resemble the number that they are predicted; the top-right example could truly be the number “4”. The bottom row is easier for a human to identify, yet still shows examples that are atypical of the standard digit “9”.</p><h3>Conclusion</h3><p>Machine learning practitioners and stakeholders often require explanations of the results of classification algorithms. We introduce the class map, a novel visualization tool that helps end-users understand how a classifier makes its decisions. We then introduce the localized class map, a model-agnostic extension of the class map. Using benchmark examples, we have seen that both the class map and the localized class map help us answer several questions about how a classifier works, such as:</p><ul><li>Does the classifier make decisions in line with an object’s difficulty ? Or, does it make mistakes on typical examples ?</li><li>Is the data relatively homogeneous, or are there a lot of challenging examples ?</li><li>Where does a classifier have confusion ?</li><li>Why does a classifier make a mistake on a particular observation ?</li></ul><p>While this post focuses on sharing the basic idea of the class map and its localized counterpart, the tool has uses beyond visualizing a single classification algorithm. It can also be used to compare different classifiers on the same data, assess the fairness of a classifier. To get a more detailed understanding of the class map, we refer to the original paper [5] and its associated <a href="https://rdrr.io/cran/classmap/man/classmap.html">R package</a>. For the localized class map, we refer to [2] and its associated <a href="https://github.com/nurakawa/localized-classmap">implementation</a>.</p><h3>Code Examples: Class Maps in R and Python</h3><p>Both versions of the class map are open-source and easy to use. The class map is implemented in the R package classmap, available on CRAN.</p><p>The localized classmap is implemented in Python and in R, and are built with popular machine learning frameworks in mind. In Python, the localized class map can be plotted for most scikit-learn classifiers. In R, the localized class map is compatible with caret . Below, we present reproducible examples in each language.</p><h3>R Example: Iris— class map</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b95c282c97120c1b94366cf649996aa0/href">https://medium.com/media/b95c282c97120c1b94366cf649996aa0/href</a></iframe><h3>Python Example: MNIST — localized class map</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83eacc156a67eabc004f36c06c5761cf/href">https://medium.com/media/83eacc156a67eabc004f36c06c5761cf/href</a></iframe><p>In R, the localized class map is implemented to be compatible with caret, a machine learning framework that contains a large number of classification models. Below, we show part of an example with the Iris dataset (full example is <a href="https://github.com/nurakawa/localized-classmap/blob/main/examples/example_iris.R">here</a>).</p><h3>R Example: Iris — localized class map</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5ccf1e7d44053889f9469184cf885ae/href">https://medium.com/media/d5ccf1e7d44053889f9469184cf885ae/href</a></iframe><p>Thanks for reading !</p><h3>References</h3><p>[1] Amina Adadi and Mohammed Berrada, <a href="https://ieeexplore.ieee.org/document/8466590">Peeking Inside the Black-Box: A Survey on Explainable Artificial Intelligence(XAI)</a> 2018, IEEE Xplore</p><p>[2] Kawa, N. <a href="https://github.com/nurakawa/localized-classmap/blob/main/msc_thesis_kawa.pdf">Visualizing Classification Results</a>, 2021, Github</p><p>[3] Lipton, Z. C., <a href="https://arxiv.org/abs/1606.03490">The mythos of model interpretability: In machine learning, the concept of interpretability is both important and slippery</a>, 2018, arXiv</p><p>[4] Napierala, K. and Stefanowski, J., <a href="https://link.springer.com/article/10.1007/s10844-015-0368-1">Types of minority class examples and their influence on learning classifiers from imbalanced data</a>, 2015, Journal of Intelligent Information Systems</p><p>[5] Raymaekers, J., Rousseeuw, P. J., and Hubert, M., <a href="https://arxiv.org/abs/2007.14495#:~:text=The%20goal%20is%20to%20visualize,regression%2C%20and%20coupling%20pairwise%20classifications.">Class maps for visualizing classification results</a>, 2021, Technometrics</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0e137a91d2c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/explainable-ai-xai-with-class-maps-d0e137a91d2c">Explainable AI (XAI) with Class Maps</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>