SVM - calculating values problem

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

SVM - calculating values problem

Benoît PELE
Hello everybody,

That is the first time that I am working on a SVM modeling and I would like to calculate by myself the result values from the SVM for each line of my database (named x_appr_svm).

First I tested a linear SVM model using the e1071 package and to calculate the individual results by myself I did the next things :
Retrieving the model coefficients  : coef_svm<-t(svm$coefs) %*% x_appr_svm[svm$index,]
Calculating the values for each line : p2<-x_appr_svm %*% t(coef_svm) - svm$rho
Using the predict function to compare : p1<-attr(predict(object=svm, newdata=x_appr_svm, decision.values=T), "decision.values")
--> p1 and p2 are the same.

Next I tested a polynomial SVM model using the same package and the same method knowing that the model parameters are :
degree=2,  gamma=0.02, coef0=0.01
The calculation of the individual values becomes (I guess) : p2<-(0.02*x_appr_svm %*% t(coef_svm)+0.01)^2-svm$rho
--> p1 and p2 are really different!

Despite of my searching, I do not understand why or where is the problem in my second p2 formula. Do you see the mistake?

Thank you for your help and have a good day, Benoit (France).

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: SVM - calculating values problem

Sarah Goslee
You could download the package code from CRAN and look yourself at what the
predict function is doing.

Sarah

On Wed, Aug 28, 2019 at 6:35 AM PELE Benoît (Acoss) <[hidden email]>
wrote:

> Hello everybody,
>
> That is the first time that I am working on a SVM modeling and I would
> like to calculate by myself the result values from the SVM for each line of
> my database (named x_appr_svm).
>
> First I tested a linear SVM model using the e1071 package and to calculate
> the individual results by myself I did the next things :
> Retrieving the model coefficients  : coef_svm<-t(svm$coefs) %*%
> x_appr_svm[svm$index,]
> Calculating the values for each line : p2<-x_appr_svm %*% t(coef_svm) -
> svm$rho
> Using the predict function to compare : p1<-attr(predict(object=svm,
> newdata=x_appr_svm, decision.values=T), "decision.values")
> --> p1 and p2 are the same.
>
> Next I tested a polynomial SVM model using the same package and the same
> method knowing that the model parameters are :
> degree=2,  gamma=0.02, coef0=0.01
> The calculation of the individual values becomes (I guess) :
> p2<-(0.02*x_appr_svm %*% t(coef_svm)+0.01)^2-svm$rho
> --> p1 and p2 are really different!
>
> Despite of my searching, I do not understand why or where is the problem
> in my second p2 formula. Do you see the mistake?
>
> Thank you for your help and have a good day, Benoit (France).
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Sarah Goslee (she/her)
http://www.sarahgoslee.com

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: SVM - calculating values problem

Benoît PELE
Finally, I did not find the detail of the “R_svmpredict” function that may be a C program but applying the function named “svmpred” in the svminternals.pdf document I solved my problem.

Thank you and best regards, Benoit.

De : Sarah Goslee <[hidden email]>
Envoyé : mercredi 28 août 2019 12:50
À : PELE Benoît (Acoss) <[hidden email]>
Cc : [hidden email]
Objet : Re: [R] SVM - calculating values problem

You could download the package code from CRAN and look yourself at what the predict function is doing.

Sarah

On Wed, Aug 28, 2019 at 6:35 AM PELE Benoît (Acoss) <[hidden email]<mailto:[hidden email]>> wrote:
Hello everybody,

That is the first time that I am working on a SVM modeling and I would like to calculate by myself the result values from the SVM for each line of my database (named x_appr_svm).

First I tested a linear SVM model using the e1071 package and to calculate the individual results by myself I did the next things :
Retrieving the model coefficients  : coef_svm<-t(svm$coefs) %*% x_appr_svm[svm$index,]
Calculating the values for each line : p2<-x_appr_svm %*% t(coef_svm) - svm$rho
Using the predict function to compare : p1<-attr(predict(object=svm, newdata=x_appr_svm, decision.values=T), "decision.values")
--> p1 and p2 are the same.

Next I tested a polynomial SVM model using the same package and the same method knowing that the model parameters are :
degree=2,  gamma=0.02, coef0=0.01
The calculation of the individual values becomes (I guess) : p2<-(0.02*x_appr_svm %*% t(coef_svm)+0.01)^2-svm$rho
--> p1 and p2 are really different!

Despite of my searching, I do not understand why or where is the problem in my second p2 formula. Do you see the mistake?

Thank you for your help and have a good day, Benoit (France).

        [[alternative HTML version deleted]]

______________________________________________
[hidden email]<mailto:[hidden email]> mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
--
Sarah Goslee (she/her)
http://www.sarahgoslee.com

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.