[R] extract hyperplan from e1071 model

Sarah Goslee @@r@h@go@lee @ending from gm@il@com
Thu Dec 20 14:59:43 CET 2018


Hi,

According to the help for svm, which you probably should have started
with, SV contains the support vectors, and index contains the position
of the support vectors in the data matrix.

As for plotting, plot.svm lets you pass additional options to plot so
that you can customize the plot to your tastes. I'm not sure if
add=TRUE is a useful option there, but you should try it. If that
doesn't meet your needs, R is open source - you can easily look at the
code for plot.svm and see what you need (basically the predicted
values on agrid, if I'm understanding your goal correctly).

Sarah

On Thu, Dec 20, 2018 at 5:16 AM Luigi Marongiu <marongiu.luigi using gmail.com> wrote:
>
> Dear all,
> I am using the package e1071 for modeling SVM. I obtain a model from
> the data and I can plot the results; the plot shows the support
> vectors (as 'X's) and the shaded areas as it should be.
> However, I don't like the plot generated from the model and I would
> like instead to have more control upon the plotting; in particular, I
> would like to draw the hyperplane on plots I have already made from
> the data available.
> Is there a way to extract the values that are used to draw the hyperplane?
> That is: plot(model) -- where model is obtained from svm() -- draws an
> area in blue and one in red based on some values provided by model;
> can I get these values so I can plot a line in a pre-existing plot?
> Also, it is possible to extract the positions of the support vectors?
> The names of the model generated by svm() are:
> > names(mod)
>  [1] "call"            "type"            "kernel"          "cost"
>  [5] "degree"          "gamma"           "coef0"           "nu"
>  [9] "epsilon"         "sparse"          "scaled"          "x.scale"
> [13] "y.scale"         "nclasses"        "levels"          "tot.nSV"
> [17] "nSV"             "labels"          "SV"              "index"
> [21] "rho"             "compprob"        "probA"           "probB"
> [25] "sigma"           "coefs"           "na.action"       "fitted"
> [29] "decision.values" "terms"
>
> Which one should I look at?
> Thank you
> --
> Best regards,
> Luigi
>
> ______________________________________________
> R-help using r-project.org 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



More information about the R-help mailing list