title: identifying miss classified values in confusion matrix in R
body: <p>I am using the caret package along with the confusionMatrix function and I would like to know if it is possible to know which are the exact values that were not clasified properly.</p>
  <p>Here is a subset of my train data</p>
  <pre><code>train_sub &lt;- structure(
    list(
      corr = c(
        0.629922866893549,
        0.632354159559817,
        0.656112138936032,
        0.4469719807955,
        0.598136079870775,
        0.314461239093862,
        0.379065842199838,
        0.347331370037428,
        0.310270891798492,
        0.361064451331448,
        0.335628455451358
      ),
      rdist = c(
        0.775733824285612,
        0.834148208687529,
        0.884167982488944,
        0.633989717138057,
        0.850225777237626,
        0.626197919283803,
        0.649597055761598,
        0.680382136363523,
        0.627828985862852,
        0.713674404108905,
        0.646094473468118
      ),
      CCF2 = c(
        0.634465565134314,
        0.722096802135009,
        0.792385621105087,
        0.46497582143802,
        0.739612023831014,
        0.470724554509749,
        0.505961260826622,
        0.527876803999064,
        0.461724328071479,
        0.564117580569802,
        0.490084457081904
      ),
      Wcorr = c(
        0.629,
        0.613,
        0.812,
        0.424,
        0.593,
        0.36,
        0.346,
        0.286,
        0.333,
        0.381,
        0.333
      ),
      Wcorr2 = c(
        0.735,
        0.743,
        0.802,
        0.588,
        0.691,
        0.632,
        0.61,
        0.599,
        0.599,
        0.632,
        0.613
      ),
      Wcorr3 = c(
        0.21,
        0.301,
        0.421,
        -0.052,
        0.169,
        -0.032,
        -0.042,-0.048,
        -0.035,
        0.006,
        -0.004
      ),
      Var = c(&quot;W&quot;, &quot;W&quot;, &quot;W&quot;, &quot;W&quot;,
              &quot;W&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;)
    ),
    row.names = c(1L, 2L,
                  3L, 5L, 7L, 214L, 215L, 216L, 217L, 218L, 221L),
    class = &quot;data.frame&quot;
  )
  </code></pre>
  <p>and here is a subset of my test data</p>
  <pre><code>test_sub &lt;- structure(
    list(
      corr = c(
        0.636658204667785,
        0.5637857758104,
        0.540558984461647,
        0.392647603023863,
        0.561801911406989,
        0.297187412065481,
        0.278864501603015,
        0.505277007007347,
        0.403811785308709,
        0.510158398354856,
        0.459607853624603
      ),
      rdist = c(
        0.887270722679019,
        0.843656768956754,
        0.815806338767273,
        0.732093571145576,
        0.832944903081762,
        0.485497073465096,
        0.454461718498521,
        0.69094669881886,
        0.627667080657035,
        0.705558894672344,
        0.620838398507191
      ),
      CCF2 = c(
        0.802017782695131,
        0.731763898271157,
        0.689402284804853,
        0.577932997250877,
        0.715111899030751,
        0.324826043263382,
        0.298456267077388,
        0.544808216945995,
        0.458148923874818,
        0.551160266327893,
        0.461228649848996
      ),
      Wcorr = c(
        0.655,
        0.536,
        0.677,
        0.556,
        0.571,
        0.29,
        0.25,
        0.484,
        0.25,
        0.515,
        0.314
      ),
      Wcorr2 = c(
        0.779,
        0.682,
        0.734,
        0.675,
        0.736,
        0.5,
        0.529,
        0.611,
        0.555,
        0.639,
        0.572
      ),
      Wcorr3 = c(
        0.368,
        0.154,
        0.266,
        0.103,
        0.224,
        -0.204,
        -0.16,
        -0.026,
        -0.149,
        0.032,
        -0.097
      ),
      Var = c(&quot;W&quot;, &quot;W&quot;, &quot;W&quot;, &quot;W&quot;, &quot;W&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;,
              &quot;B&quot;)
    ),
    row.names = c(4L, 6L, 8L, 13L, 15L, 321L, 322L, 329L,
                  334L, 341L, 344L),
    class = &quot;data.frame&quot;
  )
  </code></pre>
  <p>When I use this line,</p>
  <pre><code>confusionMatrix(reference=as.factor(test$Var),data=fittedTL,mode = &quot;everything&quot;)
  </code></pre>
  <p>With this I compute some machine learning using glmnet method (it gives the best accuracy ini my case)</p>
  <pre><code>classCtrl &lt;- trainControl(method = &quot;repeatedcv&quot;, number=10,repeats=5,classProbs =  TRUE,savePredictions = &quot;final&quot;)
  set.seed(355)
  glmnetTL &lt;- train(Var~., train_sub, method= &quot;glmnet&quot;,   trControl=classCtrl)
  glmnetTL
  </code></pre>
  <p>And finally I compute the confusion matrix on my test set:</p>
  <pre><code>predict_glmnet &lt;- predict(glmnetTL,test_sub)
  predict_glmnet
  
  CM_glmnet &lt;- confusionMatrix(reference=as.factor(test_sub$Var),data=predict_glmnet,mode = &quot;everything&quot;)
  CM_glmnet
  </code></pre>
  <p>The output of the confusion matrix is a table like so</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;"></th>
  <th style="text-align: center;">B</th>
  <th style="text-align: right;">W</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">B</td>
  <td style="text-align: center;">4</td>
  <td style="text-align: right;">0</td>
  </tr>
  <tr>
  <td style="text-align: left;">W</td>
  <td style="text-align: center;">2</td>
  <td style="text-align: right;">5</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>So here I have two predictions/classifications that are not good.</p>
  <p>Is there any way I can traceback to which row of my test set it corresponds ?</p>