title: Why are probabilities and response in ksvm in R not consistent?
body: <p>I am using <code>ksvm</code> from the kernlab package in R to predict probabilities, using the <code>type="probabilities"</code> option in <code>predict.ksvm</code>. However, I find that sometimes using <code>predict(model,observation,type="r")</code> yields not the class with the highest probability given by <code>predict(model,observation,type="p")</code>.</p>
  
  <p>Example:</p>
  
  <pre><code>&gt; predict(model,observation,type="r")
  [1] A
  Levels: A B
  &gt; predict(model,observation,type="p")
          A    B
  [1,] 0.21 0.79
  </code></pre>
  
  <p>Is this correct behavior, or a bug? If it is correct behavior, how can I estimate the most likely class from the probabilities?</p>
  
  <hr>
  
  <p>Attempt at reproducible example:</p>
  
  <pre><code>library(kernlab)
  set.seed(1000)
  # Generate fake data
  n &lt;- 1000
  x &lt;- rnorm(n)
  p &lt;- 1 / (1 + exp(-10*x))
  y &lt;- factor(rbinom(n, 1, p))
  dat &lt;- data.frame(x, y)
  tmp &lt;- split(dat, dat$y)
  # Create unequal sizes in the groups (helps illustrate the problem)
  newdat &lt;- rbind(tmp[[1]][1:100,], tmp[[2]][1:10,])
  # Fit the model using radial kernal (default)
  out &lt;- ksvm(y ~ x, data = newdat, prob.model = T)
  # Create some testing points near the boundary
  
  testdat &lt;- data.frame(x = seq(.09, .12, .01))
  # Get predictions using both methods
  responsepreds &lt;- predict(out, newdata = testdat, type = "r")
  probpreds &lt;- predict(out, testdat, type = "p")
  
  results &lt;- data.frame(x = testdat, 
                        response = responsepreds, 
                        P.x.0 = probpreds[,1], 
                        P.x.1 = probpreds[,2])
  </code></pre>
  
  <p>Output of results:</p>
  
  <pre><code>&gt; results
       x response     P.x.0     P.x.1
  1 0.09        0 0.7199018 0.2800982
  2 0.10        0 0.6988079 0.3011921
  3 0.11        1 0.6824685 0.3175315
  4 0.12        1 0.6717304 0.3282696
  </code></pre>