getting probabilities from SVM

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

getting probabilities from SVM

Roger J. Bos
I am using SVM to classify categorical data and I would like the
probabilities instead of the classification.  ?predict.svm says that its
only enabled when you train the model with it enabled, so I did that, but it
didn't work.  I can't even get it to work with iris.  The help file shows
that probability = TRUE when training the model, but doesn't show an
example.  Then I try to predict with probabilities, I still only get
classifications back.  Anyone get this to work and can help me out?


Thanks,

Roger

attach(iris)

     # alternatively the traditional interface:
     x <- subset(iris, select = -Species)
     y <- Species
     model <- svm(x, y, probability = TRUE)
     pred <- predict(model, x, probability = TRUE)

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: getting probabilities from SVM

Roger J. Bos
Finally figured it out.  You have to extract it from the attributes.
Tricky.  Thanks anyway.

> attr(pred, "prob")[1:10,]


On 2/16/06, roger bos <[hidden email]> wrote:

>
> I am using SVM to classify categorical data and I would like the
> probabilities instead of the classification.  ?predict.svm says that its
> only enabled when you train the model with it enabled, so I did that, but it
> didn't work.  I can't even get it to work with iris.  The help file shows
> that probability = TRUE when training the model, but doesn't show an
> example.  Then I try to predict with probabilities, I still only get
> classifications back.  Anyone get this to work and can help me out?
>
>
> Thanks,
>
> Roger
>
> attach(iris)
>
>      # alternatively the traditional interface:
>      x <- subset(iris, select = -Species)
>      y <- Species
>      model <- svm(x, y, probability = TRUE)
>      pred <- predict(model, x, probability = TRUE)
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: getting probabilities from SVM

David Meyer-2
In reply to this post by Roger J. Bos
> Finally figured it out.  You have to extract it from the attributes.
> Tricky.  Thanks anyway.

> attr(pred, "prob")[1:10,]

Correct.

Just for the records, the rationale behind this `tricky' design:

In addition to probabilites, predict.svm() (more precisely: libsvm) can also compute the decision values. Common ways to handle `polymorph' prediction types are, e.g, using a `type' argument in the predict() function, or to return all variants in one list object. With a `type' argument, you need several calls to predict() if you need, say, hard predictions _and_ the probabilities. On the other hand, the probability and decision values features were added to libsvm only when svm() in e1071 had already been around for a while, so returning a list instead of a vector would have broken a lot of code. So I decided to keep the `standard' predict behavior and to `hide' special predictions in an attribute. If the latter had been available from the beginning, I probably would have used the `type' approach.

Cheers,
David


On 2/16/06, roger bos <[hidden email]> wrote:
>
> I am using SVM to classify categorical data and I would like the
> probabilities instead of the classification.  ?predict.svm says that its
> only enabled when you train the model with it enabled, so I did that, but it
> didn't work.  I can't even get it to work with iris.  The help file shows
> that probability = TRUE when training the model, but doesn't show an
> example.  Then I try to predict with probabilities, I still only get
> classifications back.  Anyone get this to work and can help me out?

--
Dr. David Meyer
Department of Information Systems and Operations

Vienna University of Economics and Business Administration
Augasse 2-6, A-1090 Wien, Austria, Europe
Fax: +43-1-313 36x746
Tel: +43-1-313 36x4393
HP:  http://wi.wu-wien.ac.at/~meyer/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: getting probabilities from SVM

Roger J. Bos
Thanks for the background.  I wasn't being critical.  You actually forced me
to learn something new as I hand't used attributes before.  That's why it
took me a while to figure it out.

Thanks,

Roger


On 2/17/06, David Meyer <[hidden email]> wrote:

>
> > Finally figured it out.  You have to extract it from the attributes.
> > Tricky.  Thanks anyway.
>
> > attr(pred, "prob")[1:10,]
>
> Correct.
>
> Just for the records, the rationale behind this `tricky' design:
>
> In addition to probabilites, predict.svm() (more precisely: libsvm) can
> also compute the decision values. Common ways to handle `polymorph'
> prediction types are, e.g, using a `type' argument in the predict()
> function, or to return all variants in one list object. With a `type'
> argument, you need several calls to predict() if you need, say, hard
> predictions _and_ the probabilities. On the other hand, the probability and
> decision values features were added to libsvm only when svm() in e1071 had
> already been around for a while, so returning a list instead of a vector
> would have broken a lot of code. So I decided to keep the `standard' predict
> behavior and to `hide' special predictions in an attribute. If the latter
> had been available from the beginning, I probably would have used the `type'
> approach.
>
> Cheers,
> David
>
>
> On 2/16/06, roger bos <[hidden email]> wrote:
> >
> > I am using SVM to classify categorical data and I would like the
> > probabilities instead of the classification.  ?predict.svm says that its
> > only enabled when you train the model with it enabled, so I did that,
> but it
> > didn't work.  I can't even get it to work with iris.  The help file
> shows
> > that probability = TRUE when training the model, but doesn't show an
> > example.  Then I try to predict with probabilities, I still only get
> > classifications back.  Anyone get this to work and can help me out?
>
> --
> Dr. David Meyer
> Department of Information Systems and Operations
>
> Vienna University of Economics and Business Administration
> Augasse 2-6, A-1090 Wien, Austria, Europe
> Fax: +43-1-313 36x746
> Tel: +43-1-313 36x4393
> HP:  http://wi.wu-wien.ac.at/~meyer/
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html