<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/interpreting-machine-learning-models-with-the-lime-package-for-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2018/06/lime-package.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>Many types of machine learning classifiers, not least commonly-used techniques like ensemble models and neural networks, are notoriously difficult to interpret. If the model produces a surprising label for any given case, it's difficult to answer the question, &quot;why <em>that</em> label, and not one of the others?&quot;.</p>
<p>One approach to this dilemma is the technique known as LIME (Local Interpretable Model-Agnostic Explanations). The basic idea is that while for highly non-linear models it's impossible to give a simple explanation of the relationship between any one variable and the predicted classes at a <em>global</em> level, it might be possible to asses which variables are most influential on the classification at a <em>local</em> level, near the neighborhood of a particular data point. An procedure for doing so is described in <a rel="nofollow" href="https://arxiv.org/abs/1602.04938" target="_blank">this 2016 paper by Ribeiro et al</a>, and implemented in the <a rel="nofollow" href="https://github.com/thomasp85/lime" target="_blank">R package <strong>lime</strong></a> by Thomas Lin Pedersen and Michael Benesty (and a port of the Python package of the same name). </p>
<p>You can read about how the lime package works in the introductory vignette <em><span><a rel="nofollow" href="" target="_blank">Understanding Lime</a></span></em>, but this limerick by Mara Averick sums also things up nicely:</p>
<blockquote>
<p><em>There once was a package called lime,</em><br><em>Whose models were simply sublime,</em><br><em>It gave explanations for their variations,</em><br><em>One observation at a time.</em></p>
</blockquote>
<p>&quot;One observation at a time&quot; is the key there: given a prediction (or a collection of predictions) it will determine the variables that most support (or contradict) the predicted classification.</p>
<p><a rel="nofollow" href="http://a1.typepad.com/6a0105360ba1c6970c022ad3535ca1200c-pi" target="_blank"><img border="0" alt="Lime" title="Lime" src="http://a1.typepad.com/6a0105360ba1c6970c022ad3535ca1200c-800wi"></a></p>
<p>The lime package also works with text data: for example, you may have a model that classifies a paragraph of text as a sentiment &quot;negative&quot;, &quot;neutral&quot; or &quot;positive&quot;. In that case, lime will determine the the words in that sentence which are most important to determining (or contradicting) the classification. The package helpfully also provides a shiny app making it easy to test out different sentences and see the local effect of the model.</p>
<p>To learn more about the lime algorithm and how to use the associated R package, a great place to get started is the tutorial <a rel="nofollow" href="http://uc-r.github.io/lime" target="_blank">Visualizing ML Models with LIME</a> from the University of Cincinnati <a rel="nofollow" href="http://uc-r.github.io/" target="_blank">Business Analytics R Programming Guide</a>. The lime package is available on CRAN now, and you can always find the latest version at the GitHub repository linked below.</p>
<p>GitHub (thomasp): <a rel="nofollow" href="https://github.com/thomasp85/lime" target="_blank">lime</a> (Local Interpretable Model-Agnostic Explanations)</p>
<p> </p>
<p> </p>
<p> </p>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://blog.revolutionanalytics.com/2018/06/lime-package.html"> Revolutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/u4HaMqMDbjs" height="1"></a></div>