title: 'lime' package in R intuition
body: <p>I am going through the example (below): which is a binary classification example. I want to make sure some of my intuition is correct here as there is not much documentation regarding the <code>lime</code> package due to it being relatively new.</p>
  
  <p>Output of the example</p>
  
  <pre><code>library(xgboost)
  library(dplyr)
  library(caret)
  library(insuranceData) # example dataset https://cran.r-project.org/web/packages/insuranceData/insuranceData.pdf
  library(lime) # Local Interpretable Model-Agnostic Explanations
  set.seed(123)
  data(dataCar)
  mydb &lt;- dataCar %&gt;% select(clm, exposure, veh_value, veh_body,
                             veh_age, gender, area, agecat)
  
  label_var &lt;- "clm"  
  offset_var &lt;- "exposure"
  feature_vars &lt;- mydb %&gt;% 
    select(-one_of(c(label_var, offset_var))) %&gt;% 
    colnames()
  
  #preparing data for xgboost (one hot encoding of categorical (factor) data
  myformula &lt;- paste0( "~", paste0( feature_vars, collapse = " + ") ) %&gt;% as.formula()
  dummyFier &lt;- caret::dummyVars(myformula, data=mydb, fullRank = TRUE)
  dummyVars.df &lt;- predict(dummyFier,newdata = mydb)
  mydb_dummy &lt;- cbind(mydb %&gt;% select(one_of(c(label_var, offset_var))), 
                      dummyVars.df)
  rm(myformula, dummyFier, dummyVars.df)
  
  
  feature_vars_dummy &lt;-  mydb_dummy  %&gt;% select(-one_of(c(label_var, offset_var))) %&gt;% colnames()
  
  xgbMatrix &lt;- xgb.DMatrix(
    data = mydb_dummy %&gt;% select(feature_vars_dummy) %&gt;% as.matrix, 
    label = mydb_dummy %&gt;% pull(label_var),
    missing = "NAN")
  
  
  #model 2 : this works
  myParam2 &lt;- list(max.depth = 2,
                   eta = .01,
                   gamma = 0.001,
                   objective = 'binary:logistic',
                   eval_metric = "logloss")
  
  
  booster2 &lt;- xgb.train(
    params = myParam2, 
    data = xgbMatrix, 
    nround = 50)
  
  explainer &lt;- lime(mydb_dummy %&gt;% select(feature_vars_dummy), 
                    model = booster2)
  
  explanation &lt;- explain(mydb_dummy %&gt;% select(feature_vars_dummy) %&gt;% head,
                         explainer,
                         n_labels = 2, ###### NOTE: I added this value, not sure if it should be '=1' or '=2' for binary classification.
                         n_features = 2)
  
  
  plot_features(explanation)
  </code></pre>
  
  <p>The above code talks about insurance claims which is a classification problem, claim or not claim.</p>
  
  <p>Questions:</p>
  
  <p>What is the function of <code>n_labels</code> - I have a binary classification for my own problem so would <code>n_lables</code> correspond to <code>0</code> and <code>1</code>? </p>
  
  <p>In the example <a href="https://cran.r-project.org/web/packages/lime/vignettes/Understanding_lime.html" rel="nofollow noreferrer">here</a> the author talks about <code>malignant</code> and <code>benign</code> for the <code>labels</code>. However when I run the code on my own classification problem (<em>I make sure that there is <code>0</code>  and <code>1</code> observations in the data that I plot for <code>plot_features(explanation)</code></em>, but the <code>labels</code> do not match the true value of what that observation is...</p>
  
  <p>For my own problem I have the following <a href="https://i.stack.imgur.com/E4j8E.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E4j8E.jpg" alt="plot"></a>;</p>
  
  <p>I set <code>n_labels = 1</code> (this plot is different to the code above (but still a classification problem)).</p>
  
  <p>Here in <code>case 2</code> I have under the <code>labels header</code> a result of <code>1</code> - which, can I assume is a binary classification prediction? However when I output the actual <code>true</code> results of the binary output I have the following <code>1 0 1 0 1 0</code> which I am reading that the model predicted that <code>case 1</code> was classified as <code>0</code> and in actual fact it was a <code>1</code>.<code>case 2</code> prediction was a <code>1</code> and in fact was a <code>0</code>, <code>case 3</code> was predicted to be a <code>0</code> and infact it was a <code>1</code>, <code>case 4</code> was predicted to be a <code>0</code> and it was actually a <code>0</code> etc... is this incorrect? btw I used an <code>xgb</code> model to make predictions.</p>
  
  <p>Secondly; All the <code>0</code> cases in the plot (so cases 1, 3, 4, 5, 6) all have similar characteristics... whereas case 2 is different and it has other variables/features which affect the model (I only plot 4 variables from the model (again I do not know if they are plotted randomly or by some <code>importance score</code>)).</p>
  
  <p>I quote my analysis from the <code>Understading lime</code> <a href="https://cran.r-project.org/web/packages/lime/vignettes/Understanding_lime.html" rel="nofollow noreferrer">here</a></p>
  
  <blockquote>
    <p>In this overview it is clear to see how case 195 and 416 behave alike,
    while the third benign case (7) has an unusual large bare nuclei which
    are detracting from its status as benign without affecting the final
    prediction (indicating that the values of its other features are
    making up for this odd one). To no surprise it is clear that high
    values in the measurements are indicative of a malignant tumor.</p>
  </blockquote>
  
  <p>If somebody can give me some sort of intuition/analys of the above plot it would be a great step in the right direction for me.</p>