I have no math or computer science training.

When I run predict(svm,data,type="class")

R spits out a prediction of 1 or 0 for each row of data. What is it doing to arrive at the prediction?

Isn't the formula the dot product of the w and x plus b? It is my understanding the prediction depends on whether or not the result is greater than or less than 0. Or maybe greater than or less than 1/-1 to be outside the margin.

I have read else ware to obtain the weights the code is t(model$coefs) %*% model$SV and to find b the code is model$rho

If I go through and work out what the prediction should be manually my results do not match R's prediction. For a 2D vector I'm doing w1*x1 + w2*x2 +b. What is the correct way to work out the predictions manually?

  • 1
    $\begingroup$ Does some of this Qs with answers help? $\endgroup$ Apr 15, 2020 at 11:55
  • $\begingroup$ I don't think so, I just want to know when you do predict() and R gives a 0 or 1 for each row of data what is it doing to arrive at it's answer? $\endgroup$
    – Eric
    Apr 15, 2020 at 17:05
  • $\begingroup$ Did you try to read the code of e1071:::predict.svm? $\endgroup$ Apr 15, 2020 at 17:10
  • 1
    $\begingroup$ That's cool to know e1071:::predict.svm gives the code for a function. I am not knowledgeable enough to know what any of that code means though. Frankly, it looks like gobbledygook to me. Who is this whuber guy that just closed my thread without explanation? All that post he linked says is exactly the same copy pasted crap everything else says. From reading that to find the prediction you just take the dot product of w and x and add b, but when I do that manually my predictions do not R's predictions. So obviously I'm missing something somewhere and I'm eager to find out what it is. $\endgroup$
    – Eric
    Apr 15, 2020 at 17:51
  • $\begingroup$ Then just try to ask a much more detailed/precise question! Maybe be editing this one ... whuber is one of the moderators of this site. $\endgroup$ Apr 15, 2020 at 17:54


Browse other questions tagged or ask your own question.