Adam B. Smith
2011-Mar-04 18:54 UTC
[R] Probabilities outside [0, 1] using Support Vector Machines (SVM) in e1071
Hi All, I'm attempting to use eps-regression or nu-regression SVM to compute probabilities but the predict function applied to an svm model object returns values outside [0, 1]: Variable Data looks like: Present X02 X03 X05 X06 X07 X13 X14 X15 X18 1 0 1634 48 2245.469 -1122.0750 3367.544 11105.013 2017.306 40 23227 2 0 1402 40 2611.519 -811.2500 3422.769 10499.425 1800.475 40 13822 3 0 1379 40 2576.150 -842.8500 3419.000 10166.237 2328.756 37 14200 4 0 1869 51 2645.794 -982.2938 3628.088 9610.037 1699.656 43 20762 ... and bgEnv looks similar: X02 X03 X05 X06 X07 X13 X14 X15 X18 1 1001 39 2521.406 -38.0875 2559.494 48507.312 3925.7563 63 20616 2 1587 39 3148.056 -895.0187 4043.075 5937.669 910.9062 55 15156 3 1610 40 4116.918 172.6812 3944.237 2287.431 196.0312 51 2739 4 1495 43 3678.381 236.9250 3441.456 3298.625 23.9875 86 281 5 1564 43 3010.988 -623.6063 3634.594 3416.350 819.6375 34 3848 ... modelFormula <- as.formula(Present ~ X02 + X03 + X05 + X06 + X07 + X13 + X14 + X15 + X18) Model <- svm( modelFormula, data=Data, gamma=0.25, cost=4, nu=0.10, kernel='radial', scale=TRUE, type='nu-regression', na.action=na.omit, probability=TRUE ) bgPreds <- predict( Model, newdata=bgEnv, type='nu-regression', probability=TRUE ) bgPreds looks like: 11 12 13 14 15 16 17 18 0.54675813 0.37587560 0.39526542 0.67043587 -0.03079247 0.16696996 0.04714134 0.06989950 19 20 0.07615735 0.14923408 Notice the negative value. I can also get values >1. I had thought argument probability=TRUE would give probabilities. Any help would be greatly appreciated! Adam Adam B. Smith University of California, Berkeley
Allan Engelhardt
2011-Mar-07 08:51 UTC
[R] Probabilities outside [0, 1] using Support Vector Machines (SVM) in e1071
predict.svm only returns probabilities for model types (Model$type) less than 2, which I guess are classification models (?). In any case, the probabilities are returned as an attribute which your result clearly lacks. Trivial example:> model<- svm(Species ~ ., data = iris[-1,], probability=TRUE) > ( p<- predict(model, newdata=iris[1,], probability=TRUE) )1 setosa attr(,"probabilities") setosa versicolor virginica 1 0.9796166 0.01147175 0.008911663 Levels: setosa versicolor virginica Hope this helps a little. Allan On 04/03/11 18:54, Adam B. Smith wrote:> Hi All, > > I'm attempting to use eps-regression or nu-regression SVM to compute > probabilities but the predict function applied to an svm model object > returns values outside [0, 1]: > > Variable Data looks like: > Present X02 X03 X05 X06 X07 X13 X14 X15 X18 > 1 0 1634 48 2245.469 -1122.0750 3367.544 11105.013 2017.306 40 23227 > 2 0 1402 40 2611.519 -811.2500 3422.769 10499.425 1800.475 40 13822 > 3 0 1379 40 2576.150 -842.8500 3419.000 10166.237 2328.756 37 14200 > 4 0 1869 51 2645.794 -982.2938 3628.088 9610.037 1699.656 43 20762 > ... > > and bgEnv looks similar: > X02 X03 X05 X06 X07 X13 X14 X15 X18 > 1 1001 39 2521.406 -38.0875 2559.494 48507.312 3925.7563 63 20616 > 2 1587 39 3148.056 -895.0187 4043.075 5937.669 910.9062 55 15156 > 3 1610 40 4116.918 172.6812 3944.237 2287.431 196.0312 51 2739 > 4 1495 43 3678.381 236.9250 3441.456 3298.625 23.9875 86 281 > 5 1564 43 3010.988 -623.6063 3634.594 3416.350 819.6375 34 3848 > ... > > modelFormula<- as.formula(Present ~ X02 + X03 + X05 + X06 + X07 + X13 + > X14 + X15 + X18) > > Model<- svm( modelFormula, > data=Data, > gamma=0.25, > cost=4, > nu=0.10, > kernel='radial', > scale=TRUE, > type='nu-regression', > na.action=na.omit, > probability=TRUE > ) > > bgPreds<- predict( > Model, > newdata=bgEnv, > type='nu-regression', > probability=TRUE > ) > > bgPreds looks like: > 11 12 13 14 15 16 17 18 > 0.54675813 0.37587560 0.39526542 0.67043587 -0.03079247 0.16696996 > 0.04714134 0.06989950 > 19 20 > 0.07615735 0.14923408 > > Notice the negative value. I can also get values>1. I had thought > argument probability=TRUE would give probabilities. > > Any help would be greatly appreciated! > > Adam > > > Adam B. Smith > University of California, Berkeley > > ______________________________________________ > R-help at r-project.org mailing list > 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.