{"id":11110,"date":"2020-10-07T17:47:14","date_gmt":"2020-10-07T15:47:14","guid":{"rendered":"https:\/\/www.codemotion.com\/magazine\/?p=11110"},"modified":"2021-12-23T12:51:18","modified_gmt":"2021-12-23T11:51:18","slug":"lime-explainable-ai","status":"publish","type":"post","link":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/","title":{"rendered":"Exploring LIME Explanations and the Mathematics Behind It"},"content":{"rendered":"\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-828dcc70      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable Of Contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#introducing-lime\" class=\"uagb-toc-link__trigger\">Introducing LIME<\/a><li class=\"uagb-toc__list\"><a href=\"#a-mathematical-representation-of-lime\" class=\"uagb-toc-link__trigger\">A mathematical representation of LIME<\/a><li class=\"uagb-toc__list\"><a href=\"#getting-started-with-lime\" class=\"uagb-toc-link__trigger\">Getting started with LIME<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#installing-lime-on-google-colaboratory\" class=\"uagb-toc-link__trigger\">Installing LIME on Google Colaboratory<\/a><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#summary\" class=\"uagb-toc-link__trigger\">Summary<\/a><\/ul><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n\n<p class=\"eplus-s0qgXE\">The expansion of artificial intelligence (<span id=\"urn:enhancement-4963bfae\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/artificial_intelligence\">AI<\/span>) relies on trust. <span id=\"urn:enhancement-52f217c5\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/user_computing\">Users<\/span> will reject <span id=\"urn:enhancement-ccee458\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/machine_learning\">machine learning<\/span> (ML) systems they cannot trust. We will not trust <span id=\"urn:enhancement-b5bf17f5\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/decision-making\">decisions<\/span> made by <span id=\"urn:enhancement-78ea4024\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/scientific_modelling\">models<\/span> that do not provide clear explanations. An <span id=\"urn:enhancement-35a3c98a\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/artificial_intelligence\">AI<\/span> system must provide clear explanations, or it will gradually become obsolete.<\/p>\n\n\n\n<p class=\"eplus-CgNsIc\"><em>This article is an excerpt from the book <\/em><a href=\"https:\/\/www.amazon.com\/Hands-Explainable-XAI-Python-trustworthy\/dp\/1800208138\" target=\"_blank\" aria-label=\"undefined (opens in a new tab)\" rel=\"noreferrer noopener\"><em>Hands-on Explainable AI (XAI) with Python<\/em><\/a><em>, by Denis Rothman \u2013 a comprehensive guide to resolving the black box models in <span id=\"urn:enhancement-7185912f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/applications_of_artificial_intelligence\">AI applications<\/span> to make them fair, trustworthy, and <span id=\"urn:enhancement-46981c62\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/network_security\">secure<\/span>. The book not only covers the basic principles and tools to deploy Explainable <span id=\"urn:enhancement-438bd2b0\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/artificial_intelligence\">AI<\/span> (XAI) into your apps and reporting <span id=\"urn:enhancement-db7e730d\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/interface_computing\">interfaces<\/span>, but also enables readers to<\/em> <em>work with specific hands-on <span id=\"urn:enhancement-a652fe58\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/machine_learning\">machine learning<\/span> <span id=\"urn:enhancement-d81acdf0\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/python_programming_language\">Python<\/span> projects that are strategically arranged to enhance their grasp of <span id=\"urn:enhancement-51b47e01\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/artificial_intelligence\">AI<\/span> results analysis.&nbsp;&nbsp;<\/em><\/p>\n\n\n\n<p class=\"eplus-x4Jlo5\">Local Interpretable Model-agnostic Explanations (LIME)&#8217;s approach aims at reducing the distance between <span id=\"urn:enhancement-79fcfbed\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/artificial_intelligence\">AI<\/span> and humans. LIME is people oriented like SHAP and WIT. LIME focuses on two main areas: trusting a <span id=\"urn:enhancement-1683a23a\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> and trusting a <span id=\"urn:enhancement-ade3e632\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span>. LIME provides a unique <strong>explainable <span id=\"urn:enhancement-6529e2bb\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/artificial_intelligence\">AI<\/span><\/strong> (XAI) algorithm that interprets <span id=\"urn:enhancement-39b9b4\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">predictions<\/span> locally.<\/p>\n\n\n\n<h2 class=\"eplus-czjJ7i wp-block-heading\" id=\"h-introducing-lime\">Introducing LIME<\/h2>\n\n\n\n<p class=\"eplus-MAowbH\"><strong>LIME<\/strong> stands for <strong>Local Interpretable Model-Agnostic Explanations<\/strong>. LIME explanations can help a <span id=\"urn:enhancement-fab54c61\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/user_computing\">user<\/span> trust an <span id=\"urn:enhancement-6539eea7\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/artificial_intelligence\">AI<\/span> system. A <a href=\"\/why-do-some-machine-learning-models-fail\">machine learning model<\/a> often trains at least 100 <span id=\"urn:enhancement-c0c64420\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">features<\/span> to reach a <span id=\"urn:enhancement-290c892f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span>. Showing all these <span id=\"urn:enhancement-9a001c8\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">features<\/span> in an <span id=\"urn:enhancement-bf55fc9a\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/interface_computing\">interface<\/span> makes it nearly impossible for a <span id=\"urn:enhancement-d16d6f28\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/user_computing\">user<\/span> to analyze the result visually.<\/p>\n\n\n\n<p class=\"eplus-uAT5rC\">While learning <em>Microsoft Azure <span id=\"urn:enhancement-7356fb21\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/machine_learning\">Machine Learning<\/span> Model Interpretability with SHAP<\/em>, we used SHAP to calculate the marginal contribution of a <span id=\"urn:enhancement-c2ebe63\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">feature<\/span> to the <span id=\"urn:enhancement-5360bfcb\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> and for a given <span id=\"urn:enhancement-ee9a3844\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span>. The Shapley value of a <span id=\"urn:enhancement-81d7fbd0\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">feature<\/span> represents its contribution to one or several sets of <span id=\"urn:enhancement-d41eb410\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">features<\/span>. LIME has a different approach.<\/p>\n\n\n\n<p class=\"eplus-8fo6hz\">LIME wants to find out whether a <span id=\"urn:enhancement-4f9fa14f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> is <em>locally faithful regardless of the <span id=\"urn:enhancement-73a4cf7f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span><\/em>. Local fidelity verifies how a <span id=\"urn:enhancement-5088c1b4\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> represents the <span id=\"urn:enhancement-4f3e655f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">features<\/span> around a <span id=\"urn:enhancement-7ffaacb4\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span>. Local fidelity might not fit the <span id=\"urn:enhancement-47136a0\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> globally, but it explains how the <span id=\"urn:enhancement-59a57ea3\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span> was made. In the same way, a global explanation of the <span id=\"urn:enhancement-26b7b0ca\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> might not explain a local <span id=\"urn:enhancement-4ff26336\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span>.<\/p>\n\n\n\n<p class=\"eplus-tOZKPM\">For example, we helped a doctor conclude that a patient was infected by the West Nile virus in previous chapters in the book.<\/p>\n\n\n\n<p class=\"eplus-QggWjY\">Our global feature set was as follows:<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-uZ8WtK\"><em><span id=\"urn:enhancement-ccf56ffb\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">Features<\/span> = {colored sputum, cough, fever, headache, days, france, chicago, class}<\/em><\/p>\n\n\n\n<p class=\"eplus-xycaRr\">Our global assumption was that the following main <span id=\"urn:enhancement-d606152\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">features<\/span> led to the conclusion with a high probability value that the patient was infected with the West Nile virus:<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-qA5kvZ\"><em><span id=\"urn:enhancement-af782cbc\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">Features<\/span> = {bad cough, high fever, bad headache, many days, chicago=true}<\/em><\/p>\n\n\n\n<p class=\"eplus-wG3bKO\">Our <span id=\"urn:enhancement-4fd93427\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">predictions<\/span> relied on that ground truth.<\/p>\n\n\n\n<p class=\"eplus-i9CaCx\">But was this global ground truth always verified locally? What if a <span id=\"urn:enhancement-98083e3a\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span> was true for the West Nile virus with a slightly different set of <span id=\"urn:enhancement-b5f3cd1f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">features<\/span>\u2014how could we explain that locally?<\/p>\n\n\n\n<p class=\"eplus-xYHbkv\">LIME will explore the local vicinity of a <span id=\"urn:enhancement-f9363e0\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span> to explain it and analyze its local fidelity.<\/p>\n\n\n\n<p class=\"eplus-xyANAM\">For example, suppose a <span id=\"urn:enhancement-f45b049b\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span> was a <span id=\"urn:enhancement-20d3165b\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/false_positives_and_false_negatives\">true positive<\/span> for the West Nile virus but not precisely for the same reasons as our global <span id=\"urn:enhancement-9f6d1bdd\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span>. LIME will search the vicinity of the instance of the <span id=\"urn:enhancement-f453b299\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span> to explain the <span id=\"urn:enhancement-738c4e98\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/decision-making\">decision<\/span> the <span id=\"urn:enhancement-246dffaa\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> made.<\/p>\n\n\n\n<p class=\"eplus-v2WGeT\">In this case, LIME could find a high <span id=\"urn:enhancement-6f7dd5df\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/probability\">probability<\/span> of the following <span id=\"urn:enhancement-769ed62a\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">features<\/span>:<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-7eJAYy\"><em>Local explanation = {high fever, mild sputum, mild headache, chicago=true}<\/em><\/p>\n\n\n\n<p class=\"eplus-aO50NG\">We know that a patient with a high fever with a headache that was in Chicago points to the West Nile virus. The presence of chills might provide an explanation as well, although the global <span id=\"urn:enhancement-19d4fedf\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> had a different view. Locally, the <span id=\"urn:enhancement-1b95b205\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span> is faithful, although globally, our <span id=\"urn:enhancement-74735532\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span>&#8216;s output was positive when many days and bad cough were present, and mild sputum was absent.<\/p>\n\n\n\n<p class=\"eplus-9veV9q\">The <span id=\"urn:enhancement-f7e4ed28\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span> is thus locally faithful to the <span id=\"urn:enhancement-8d40b2d1\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span>. It has inherited the global <span id=\"urn:enhancement-8fac13e4\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">feature<\/span> attributes that LIME will detect and explain locally.<\/p>\n\n\n\n<p class=\"eplus-SGNJUH\">In this example, LIME did not take the <span id=\"urn:enhancement-5ff64d60\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> into <span id=\"urn:enhancement-35b694ce\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/user_computing\">account<\/span>. LIME used the global <span id=\"urn:enhancement-f947687d\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">features<\/span> involved in a <span id=\"urn:enhancement-41e3ebb2\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span> and the local instance of the <span id=\"urn:enhancement-fea93dde\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span> to explain the output. In that sense, LIME is a <span id=\"urn:enhancement-7b9bf080\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span>-agnostic <span id=\"urn:enhancement-f510344\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> explainer.<\/p>\n\n\n\n<p class=\"eplus-6tbmia\">We now have an intuitive <span id=\"urn:enhancement-46795ed4\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/understanding\">understanding<\/span> of what Local Interpretable Model-Agnostic Explanations are. We can now formalize LIME mathematically.<\/p>\n\n\n\n<h2 class=\"eplus-CA01ak wp-block-heading\" id=\"h-a-mathematical-representation-of-lime\">A mathematical representation of LIME<\/h2>\n\n\n\n<div class=\"wp-block-image eplus-ERUXpw\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/math-1024x576.jpg\" alt=\"\" class=\"wp-image-11127\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/math-1024x576.jpg 1024w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/math-300x169.jpg 300w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/math-768x432.jpg 768w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/math-896x504.jpg 896w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/math-400x225.jpg 400w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/math.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p class=\"eplus-gR29bu\">In this section, we will translate our intuitive understanding of LIME into a mathematical expression of LIME.<\/p>\n\n\n\n<p class=\"eplus-FBCGut\">The original, global representation of an instance <em>x<\/em> can be represented as follows:<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-mluxiS\"><em>x \u2208 R<sup>d<\/sup><\/em><\/p>\n\n\n\n<p class=\"eplus-st4r6D\">However, an interpretable representation of an instance is a binary vector:<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-wPwqme\"><em>x \u2208  {0, 1} <sup>d<\/sup><\/em><\/p>\n\n\n\n<p class=\"eplus-PNYm4B\">The interpretable representation determines the local presence or absence of a <span id=\"urn:enhancement-cc7af2d8\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">feature<\/span> or several <span id=\"urn:enhancement-a051bfc8\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">features<\/span>.<\/p>\n\n\n\n<p class=\"eplus-cEYakj\">Let&#8217;s now consider the <span id=\"urn:enhancement-d388023d\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span>-agnostic property of LIME. <em>g<\/em> represents a machine learning <span id=\"urn:enhancement-785deb48\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span>. <em>G<\/em> represents a set of <span id=\"urn:enhancement-69420188\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/scientific_modelling\">models<\/span> containing <em>g<\/em> among other <span id=\"urn:enhancement-f0b0b922\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/scientific_modelling\">models<\/span>:<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-Als39e\"><em>g \u2208 G<\/em><\/p>\n\n\n\n<p class=\"eplus-A4n7ZE\">As such, LIME&#8217;s algorithm will interpret any other <span id=\"urn:enhancement-61764f90\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> in the same manner.<\/p>\n\n\n\n<p class=\"eplus-qtdHtc\">The domain of <em>g<\/em> being a binary vector, we can represent it as follows:<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-A4E9ul\"><em>g, {0, 1} <sup>d<sup>n<\/sup><\/sup><\/em><\/p>\n\n\n\n<p class=\"eplus-FPFdPc\">Now, we face a difficult problem! The complexity of <em>g \u2208 G<\/em> might create difficulties in analyzing the vicinity of an instance. We must take this <span id=\"urn:enhancement-6a4b06bb\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/risk_factor_computing\">factor<\/span> into <span id=\"urn:enhancement-4a2fb2b7\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/user_computing\">account<\/span>. We will note the complexity of an interpretation of a <span id=\"urn:enhancement-57054415\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> as follows:<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-3bTOwe\"><em>\u03a9(g)<\/em><\/p>\n\n\n\n<p class=\"eplus-LtREca\">We encountered such a complexity program in <em>one of our previous chapters<\/em>, <em>White Box XAI for <span id=\"urn:enhancement-d0c4bc42\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/artificial_intelligence\">AI<\/span> Bias and Ethics<\/em>, when interpreting decision trees. When we began to explain the structure of a decision tree, we found that &#8220;the default output of a default decision tree structure challenges a <span id=\"urn:enhancement-433969a1\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/user_computing\">user<\/span>&#8216;s ability to understand the algorithm.&#8221; In <em>that situation<\/em>, we fine-tuned the decision tree&#8217;s parameters to limit the complexity of the output to explain.<\/p>\n\n\n\n<p class=\"eplus-y0se7H\">We thus need to measure the complexity of a <span id=\"urn:enhancement-884e8080\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> with <em>\u03a9(g)<\/em>. High <span id=\"urn:enhancement-d40e3f1f\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> complexity can hinder <span id=\"urn:enhancement-597345af\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/artificial_intelligence\">AI<\/span> explanations and interpretations of a <span id=\"urn:enhancement-5f5c23d7\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/probability\">probability<\/span> function <em>f<\/em>(<em>x<\/em>). <em>\u03a9(g)<\/em> must be reasonably low enough for humans to be able to interpret a <span id=\"urn:enhancement-a39c6c6d\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">prediction<\/span>.<\/p>\n\n\n\n<p class=\"eplus-gmu1fw\"><em>f<\/em>(<em>x<\/em>) defines the <span id=\"urn:enhancement-6b76df27\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/probability\">probability<\/span> that <em>x<\/em> belongs to the binary vector we defined previously, as follows:<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-4fReVE\"><em>x&#8217; \u2208 {0, 1}<sup>d&#8217;<\/sup><\/em><\/p>\n\n\n\n<p class=\"eplus-mxf4j4\">The <span id=\"urn:enhancement-dfbca61e\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> can thus also be defined as follows:<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-ZAqLuG\"><em>f = R<sup>d<\/sup> \u2192 R<\/em><\/p>\n\n\n\n<p class=\"eplus-LJ5kHq\">Now, we need to add an instance <em>z<\/em> to see how <em>x<\/em> fits in this instance. We must measure the locality around <em>x<\/em>. For example, consider the <span id=\"urn:enhancement-4f233c2d\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/feature_machine_learning\">features<\/span> (in bold) in the two following sentences:<\/p>\n\n\n\n<ul class=\"eplus-GdQmyg wp-block-list\"><li><strong>Sentence 1<\/strong>: <em>We danced all night; it was like in the movie Saturday Night <\/em><strong><em>Fever<\/em><\/strong><em>, or that movie called <\/em><strong><em>Chicago<\/em><\/strong><em> with that murder scene that sent <\/em><strong><em>chills<\/em><\/strong><em> down my spine. I listened to music for <\/em><strong><em>days<\/em><\/strong><em> when I was a teenager.<\/em><\/li><li><strong>Sentence 2<\/strong>: <em>Doctor, when I was in <\/em><strong><em>Chicago<\/em><\/strong><em>, I hardly noticed a <\/em><strong><em>mosquito<\/em><\/strong><em> bit me, then when I got back to France, I came up with a <\/em><strong><em>fever<\/em><\/strong><em>.<\/em><\/li><\/ul>\n\n\n\n<p class=\"eplus-wO38ZE\"><strong>Sentence 2<\/strong> leads to a West Nile virus diagnosis. However, a <span id=\"urn:enhancement-410e2565\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/conceptual_model\">model<\/span> g could <span id=\"urn:enhancement-d6f01eb3\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/prediction\">predict<\/span> that <strong>Sentence 1<\/strong> is a <span id=\"urn:enhancement-11af2279\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/false_positives_and_false_negatives\">true positive<\/span> as well. The same could be said of the following <strong>Sentence 3<\/strong>:<\/p>\n\n\n\n<ul class=\"eplus-hVGD9M wp-block-list\"><li><strong>Sentence 3<\/strong>: <em>I just got back from Italy, have a bad <\/em><strong><em>fever<\/em><\/strong><em>, and <\/em><strong><em>difficulty breathing<\/em><\/strong><em>.<\/em><\/li><\/ul>\n\n\n\n<p class=\"eplus-V7EMP6\"><strong>Sentence 3<\/strong> leads to a <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/machine-learning-dev\/epidemic-intelligence-data-models-and-machine-learning-in-the-age-of-coronavirus\/\">COVID-19 diagnosis<\/a> that could be a <span id=\"urn:enhancement-159cd393\" class=\"textannotation disambiguated wl-thing\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/false_positives_and_false_negatives\">false positive<\/span> or not. I will not elaborate while in isolation in France at the time this book is in writing. It would not be ethical to make mathematical models for educational purposes in such difficult times for hundreds of millions of us around the world.<\/p>\n\n\n\n<p class=\"eplus-zesxFK\">In any case, we can see the importance of a proximity measurement between an instance <em>z<\/em> and the locality around <em>x<\/em>. We will define this proximity measurement as follows:<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-3BzXqa\">\u220f<sub>x<\/sub>(z)<\/p>\n\n\n\n<p class=\"eplus-yox2su\">We now have all the variables we need to define LIME, except one important one. How faithful is this prediction to the global ground truth of our model? Can we explain why it is trustworthy? The answer to our question will be to determine how unfaithful a model g can be when calculating <em>f<\/em> in the locality <em>\u220f<sub>x<\/sub><\/em>.<\/p>\n\n\n\n<p class=\"eplus-1XfjsB\">For all we know, a prediction could be a false positive! Or the prediction could be a false negative! Or even worse, the prediction could be a true positive or negative for the wrong reasons. This shows how unfaithful g can be.<\/p>\n\n\n\n<p class=\"eplus-SeugMj\">We will measure unfaithfulness with the letter L.<\/p>\n\n\n\n<p class=\"eplus-k1KWnJ\"><em>L(f, g, \u220f<sub>x<\/sub>)<\/em> will measure how unfaithful g is when making approximations of <em>f<\/em> in the locality we defined as <em>\u220f<sub>x<\/sub><\/em>.<\/p>\n\n\n\n<p class=\"eplus-B4yNQL\">We must minimize unfaithfulness with <em>L(f, g, \u220f<sub>x<\/sub>)<\/em> and find how to keep the complexity <em>\u03a9(g)<\/em> as low as possible.<\/p>\n\n\n\n<p class=\"eplus-PL3Lol\">Finally, we can define an explanation E generated by LIME as follows:<\/p>\n\n\n\n<p class=\"has-text-align-center eplus-n65qPi\"><em>E(x) = L(f, g, \u220f<sub>x<\/sub>) + \u03a9(g)<\/em><\/p>\n\n\n\n<p class=\"eplus-EWQXkW\">LIME will draw samples weighted by <em>\u220f<sub>x<\/sub><\/em> to optimize the equation to produce the best interpretation and explanations <em>E(x)<\/em> regardless of the model implemented.<\/p>\n\n\n\n<p class=\"eplus-3gTBnZ\">LIME can be applied to various models, fidelity functions, and complexity measures. However, LIME&#8217;s approach will follow the method we have defined.<\/p>\n\n\n\n<p class=\"eplus-n278Ef\">For more on LIME theory, consult the <em>References<\/em> section at the end of this chapter.<\/p>\n\n\n\n<p class=\"eplus-pmrotb\">We can now get started with this intuitive view and mathematical representation of LIME in mind!<\/p>\n\n\n\n<h2 class=\"eplus-FxZX6I wp-block-heading\" id=\"h-getting-started-with-lime\">Getting started with LIME<\/h2>\n\n\n\n<div class=\"wp-block-image eplus-NdOK7d\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/dev-1024x576.jpg\" alt=\"\" class=\"wp-image-11130\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/dev-1024x576.jpg 1024w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/dev-300x169.jpg 300w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/dev-768x432.jpg 768w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/dev-896x504.jpg 896w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/dev-400x225.jpg 400w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/dev.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p class=\"eplus-DtKfDw\">In this section, we will install LIME using <em>LIME.ipynb<\/em>, a <strong>Jupyter Notebook on Google Colaboratory<\/strong>. We will then retrieve the 20 newsgroups dataset from sklearn.datasets.<\/p>\n\n\n\n<p class=\"eplus-3XRBd1\">We will read the dataset and vectorize it.<\/p>\n\n\n\n<p class=\"eplus-PAfQCy\">The process is a standard scikit-learn approach that you can save and use as a template for other projects in which you implement other scikit-learn models.<\/p>\n\n\n\n<p class=\"eplus-lNjOMB\">We have already used this process in <em>a previous chapter<\/em>, <em>Microsoft Azure Machine Learning Model Interpretability with SHAP<\/em>. In this chapter, we will not examine the dataset from an ethical perspective. I chose one with no ethical ambiguity.<\/p>\n\n\n\n<p class=\"eplus-vGzEB1\">We will directly install LIME, then import and vectorize the dataset.<\/p>\n\n\n\n<p class=\"eplus-RpKBd4\">Let&#8217;s now start by installing LIME on Google Colaboratory.<\/p>\n\n\n\n<h3 class=\"eplus-CZ0tnt wp-block-heading\" id=\"h-installing-lime-on-google-colaboratory\">Installing LIME on Google Colaboratory<\/h3>\n\n\n\n<p class=\"eplus-ei5PoA\">Open <em>LIME.ipynb<\/em>. We will be using LIME.ipynb throughout this chapter. The first cell contains the installation command:<\/p>\n\n\n<pre class=\"wp-block-code eplus-bw0coO\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"># <span class=\"hljs-keyword\">@title<\/span> Installing LIME\n<span class=\"hljs-attribute\">try:<\/span>\n  import lime\n<span class=\"hljs-attribute\">except:<\/span>\n  print(<span class=\"hljs-string\">\"Installing LIME\"<\/span>)\n  !pip install lime<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"eplus-uXA5m3\">The try\/except will try to import lime. If lime is not installed, the program will crash. In this code, except will trigger <code>!pip install lime<\/code>.<\/p>\n\n\n\n<p class=\"eplus-vjJ80C\">Google Colaboratory deletes some libraries and modules when you restart it, as well as the current variables of a notebook. We then need to reinstall some packages. This piece of code will make the process seamless.<\/p>\n\n\n\n<h2 class=\"eplus-ACf5mj wp-block-heading\" id=\"h-summary\">Summary<\/h2>\n\n\n\n<p class=\"eplus-nzzI77\">In this article, we first got introduced to LIME and how it functions. Once we covered the fundamentals, we further understood how LIME is represented mathematically.&nbsp; Finally, we concluded&nbsp; by learning how to begin applying the benefits of LIME in our AI projects.<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>The expansion of artificial intelligence (AI) relies on trust. Users will reject machine learning (ML) systems they cannot trust. We will not trust decisions made by models that do not provide clear explanations. An AI system must provide clear explanations, or it will gradually become obsolete. This article is an excerpt from the book Hands-on&#8230; <a class=\"more-link\" href=\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/\">Read more<\/a><\/p>\n","protected":false},"author":111,"featured_media":11117,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":6,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_uag_custom_page_level_css":"","_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[46],"tags":[68],"collections":[],"class_list":{"0":"post-11110","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-ai-ml","8":"tag-python","9":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Exploring LIME Explanations and the Mathematics Behind It - Codemotion<\/title>\n<meta name=\"description\" content=\"Local Interpretable Model-agnostic Explanations (LIME)&#039;s approach aims at reducing the distance between AI and humans, by means of explainable AI.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Exploring LIME Explanations and the Mathematics Behind It\" \/>\n<meta property=\"og:description\" content=\"Local Interpretable Model-agnostic Explanations (LIME)&#039;s approach aims at reducing the distance between AI and humans, by means of explainable AI.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/\" \/>\n<meta property=\"og:site_name\" content=\"Codemotion Magazine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Codemotion.Italy\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-07T15:47:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-23T11:51:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Denis Rothman\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:site\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Denis Rothman\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/lime-explainable-ai\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/lime-explainable-ai\\\/\"},\"author\":{\"name\":\"Denis Rothman\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/person\\\/2cbe0ffab31de96298a43641dcd312f3\"},\"headline\":\"Exploring LIME Explanations and the Mathematics Behind It\",\"datePublished\":\"2020-10-07T15:47:14+00:00\",\"dateModified\":\"2021-12-23T11:51:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/lime-explainable-ai\\\/\"},\"wordCount\":1758,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/lime-explainable-ai\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/Senza-titolo-1-1-scaled.jpg\",\"keywords\":[\"Python\"],\"articleSection\":[\"AI\\\/ML\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/lime-explainable-ai\\\/\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/lime-explainable-ai\\\/\",\"name\":\"Exploring LIME Explanations and the Mathematics Behind It - Codemotion\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/lime-explainable-ai\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/lime-explainable-ai\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/Senza-titolo-1-1-scaled.jpg\",\"datePublished\":\"2020-10-07T15:47:14+00:00\",\"dateModified\":\"2021-12-23T11:51:18+00:00\",\"description\":\"Local Interpretable Model-agnostic Explanations (LIME)'s approach aims at reducing the distance between AI and humans, by means of explainable AI.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/lime-explainable-ai\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/lime-explainable-ai\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/lime-explainable-ai\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/Senza-titolo-1-1-scaled.jpg\",\"contentUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/Senza-titolo-1-1-scaled.jpg\",\"width\":1200,\"height\":675,\"caption\":\"machine learning math LIME\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/lime-explainable-ai\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"AI\\\/ML\",\"item\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Machine Learning\",\"item\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/ai-ml\\\/machine-learning\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Exploring LIME Explanations and the Mathematics Behind It\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#website\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/\",\"name\":\"Codemotion Magazine\",\"description\":\"We code the future. Together\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#organization\",\"name\":\"Codemotion\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/codemotionlogo.png\",\"contentUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/codemotionlogo.png\",\"width\":225,\"height\":225,\"caption\":\"Codemotion\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Codemotion.Italy\\\/\",\"https:\\\/\\\/x.com\\\/CodemotionIT\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/person\\\/2cbe0ffab31de96298a43641dcd312f3\",\"name\":\"Denis Rothman\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a975062492d425c1aa872ce85a5efd71c5556bd10196070d6d6de5496f2b46b6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a975062492d425c1aa872ce85a5efd71c5556bd10196070d6d6de5496f2b46b6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a975062492d425c1aa872ce85a5efd71c5556bd10196070d6d6de5496f2b46b6?s=96&d=mm&r=g\",\"caption\":\"Denis Rothman\"},\"description\":\"Denis Rothman graduated from Sorbonne University and Paris-Diderot University, writing one of the very first word2vector embedding solutions. He began his career authoring one of the first AI cognitive natural language processing (NLP) chatbots applied as a language teacher for Mo\u00ebt et Chandon and other companies. He has also authored an AI resource optimizer for IBM and apparel producers. He then authored an advanced planning and scheduling (APS) solution that is used worldwide. Denis is an expert in explainable AI (XAI), having added interpretable mandatory, acceptance-based explanation data and explanation interfaces to the solutions implemented for major corporate aerospace, apparel, and supply chain projects.\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/author\\\/denis-rothman\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Exploring LIME Explanations and the Mathematics Behind It - Codemotion","description":"Local Interpretable Model-agnostic Explanations (LIME)'s approach aims at reducing the distance between AI and humans, by means of explainable AI.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/","og_locale":"en_US","og_type":"article","og_title":"Exploring LIME Explanations and the Mathematics Behind It","og_description":"Local Interpretable Model-agnostic Explanations (LIME)'s approach aims at reducing the distance between AI and humans, by means of explainable AI.","og_url":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/","og_site_name":"Codemotion Magazine","article_publisher":"https:\/\/www.facebook.com\/Codemotion.Italy\/","article_published_time":"2020-10-07T15:47:14+00:00","article_modified_time":"2021-12-23T11:51:18+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled.jpg","type":"image\/jpeg"}],"author":"Denis Rothman","twitter_card":"summary_large_image","twitter_creator":"@CodemotionIT","twitter_site":"@CodemotionIT","twitter_misc":{"Written by":"Denis Rothman","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/#article","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/"},"author":{"name":"Denis Rothman","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/2cbe0ffab31de96298a43641dcd312f3"},"headline":"Exploring LIME Explanations and the Mathematics Behind It","datePublished":"2020-10-07T15:47:14+00:00","dateModified":"2021-12-23T11:51:18+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/"},"wordCount":1758,"publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled.jpg","keywords":["Python"],"articleSection":["AI\/ML"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/","url":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/","name":"Exploring LIME Explanations and the Mathematics Behind It - Codemotion","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/#primaryimage"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled.jpg","datePublished":"2020-10-07T15:47:14+00:00","dateModified":"2021-12-23T11:51:18+00:00","description":"Local Interpretable Model-agnostic Explanations (LIME)'s approach aims at reducing the distance between AI and humans, by means of explainable AI.","breadcrumb":{"@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/#primaryimage","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled.jpg","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled.jpg","width":1200,"height":675,"caption":"machine learning math LIME"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/lime-explainable-ai\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codemotion.com\/magazine\/"},{"@type":"ListItem","position":2,"name":"AI\/ML","item":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/"},{"@type":"ListItem","position":3,"name":"Machine Learning","item":"https:\/\/www.codemotion.com\/magazine\/ai-ml\/machine-learning\/"},{"@type":"ListItem","position":4,"name":"Exploring LIME Explanations and the Mathematics Behind It"}]},{"@type":"WebSite","@id":"https:\/\/www.codemotion.com\/magazine\/#website","url":"https:\/\/www.codemotion.com\/magazine\/","name":"Codemotion Magazine","description":"We code the future. Together","publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codemotion.com\/magazine\/#organization","name":"Codemotion","url":"https:\/\/www.codemotion.com\/magazine\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","width":225,"height":225,"caption":"Codemotion"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Codemotion.Italy\/","https:\/\/x.com\/CodemotionIT"]},{"@type":"Person","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/2cbe0ffab31de96298a43641dcd312f3","name":"Denis Rothman","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a975062492d425c1aa872ce85a5efd71c5556bd10196070d6d6de5496f2b46b6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a975062492d425c1aa872ce85a5efd71c5556bd10196070d6d6de5496f2b46b6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a975062492d425c1aa872ce85a5efd71c5556bd10196070d6d6de5496f2b46b6?s=96&d=mm&r=g","caption":"Denis Rothman"},"description":"Denis Rothman graduated from Sorbonne University and Paris-Diderot University, writing one of the very first word2vector embedding solutions. He began his career authoring one of the first AI cognitive natural language processing (NLP) chatbots applied as a language teacher for Mo\u00ebt et Chandon and other companies. He has also authored an AI resource optimizer for IBM and apparel producers. He then authored an advanced planning and scheduling (APS) solution that is used worldwide. Denis is an expert in explainable AI (XAI), having added interpretable mandatory, acceptance-based explanation data and explanation interfaces to the solutions implemented for major corporate aerospace, apparel, and supply chain projects.","url":"https:\/\/www.codemotion.com\/magazine\/author\/denis-rothman\/"}]}},"featured_image_src":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled-600x400.jpg","featured_image_src_square":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled-600x600.jpg","author_info":{"display_name":"Denis Rothman","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/denis-rothman\/"},"uagb_featured_image_src":{"full":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled.jpg",1200,675,false],"thumbnail":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled-150x150.jpg",150,150,true],"medium":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled-768x432.jpg",768,432,true],"large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled.jpg",1200,675,false],"2048x2048":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled.jpg",1200,675,false],"small-home-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled.jpg",100,56,false],"sidebar-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled-180x128.jpg",180,128,true],"genesis-singular-images":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled-896x504.jpg",896,504,true],"archive-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled-400x225.jpg",400,225,true],"gb-block-post-grid-landscape":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled-600x400.jpg",600,400,true],"gb-block-post-grid-square":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/10\/Senza-titolo-1-1-scaled-600x600.jpg",600,600,true]},"uagb_author_info":{"display_name":"Denis Rothman","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/denis-rothman\/"},"uagb_comment_info":0,"uagb_excerpt":"The expansion of artificial intelligence (AI) relies on trust. Users will reject machine learning (ML) systems they cannot trust. We will not trust decisions made by models that do not provide clear explanations. An AI system must provide clear explanations, or it will gradually become obsolete. This article is an excerpt from the book Hands-on&#8230;&hellip;","lang":"en","_links":{"self":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/11110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/users\/111"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/comments?post=11110"}],"version-history":[{"count":7,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/11110\/revisions"}],"predecessor-version":[{"id":15072,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/11110\/revisions\/15072"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media\/11117"}],"wp:attachment":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media?parent=11110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/categories?post=11110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/tags?post=11110"},{"taxonomy":"collections","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/collections?post=11110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}