Support for the kernlab error carriage machine translation vector support, the probability class of computing failed; NA return

I have some data, and the Y variable is a factor - good or bad. I create a vector support machine using the train method from the caret package. Using the "train" function, I was able to refine the values ​​of various settings and get the final vector support machine. For test data, I can predict the "class". But when I try to predict the probabilities for the test data, I get below errors (for example, my model tells me that the 1st data point in the test data has y = 'good', but I want to know what is the probability of getting a "good", ... in the general case, if the vector machine is supported, the model will calculate the probability of forecasting. If the variable Y has 2 results, then the model will predict the probability of each result. The outcome that has the maximum probability is considered as the final decision)

**Warning message: In probFunction(method, modelFit, ppUnk) : kernlab class probability calculations failed; returning NAs** 

code example below

 library(caret) trainset <- data.frame( class=factor(c("Good", "Bad", "Good", "Good", "Bad", "Good", "Good", "Good", "Good", "Bad", "Bad", "Bad")), age=c(67, 22, 49, 45, 53, 35, 53, 35, 61, 28, 25, 24)) testset <- data.frame( class=factor(c("Good", "Bad", "Good" )), age=c(64, 23, 50)) library(kernlab) set.seed(231) ### finding optimal value of a tuning parameter sigDist <- sigest(class ~ ., data = trainset, frac = 1) ### creating a grid of two tuning parameters, .sigma comes from the earlier line. we are trying to find best value of .C svmTuneGrid <- data.frame(.sigma = sigDist[1], .C = 2^(-2:7)) set.seed(1056) svmFit <- train(class ~ ., data = trainset, method = "svmRadial", preProc = c("center", "scale"), tuneGrid = svmTuneGrid, trControl = trainControl(method = "repeatedcv", repeats = 5)) ### svmFit finds the optimal values of tuning parameters and builds the model using the best parameters ### to predict class of test data predictedClasses <- predict(svmFit, testset ) str(predictedClasses) ### predict probablities but i get an error predictedProbs <- predict(svmFit, newdata = testset , type = "prob") head(predictedProbs) 

a new question below this line: according to the output below there are 9 support vectors. how to recognize from 12 points of training data that are these 9?

 svmFit$finalModel 

Support for Vector Machine object of class "ksvm"

SV type: C-svc (classification) parameter: value C = 1

Gaussian function of the core of the radial basis. Hyperparameter: sigma = 0.72640759446315

Number of supported vectors: 9

Target function value: -5.6994 Learning error: 0.083333

+4
source share
1 answer

In the trip control statement, you must indicate whether you want to return class probabilities classProbs = TRUE .

 svmFit <- train(class ~ ., data = trainset, method = "svmRadial", preProc = c("center", "scale"), tuneGrid = svmTuneGrid, trControl = trainControl(method = "repeatedcv", repeats = 5, classProbs = TRUE)) predictedClasses <- predict(svmFit, testset ) predictedProbs <- predict(svmFit, newdata = testset , type = "prob") 

gives the probability of being in the Bad or Good class in the test dataset as follows:

 print(predictedProbs) Bad Good 1 0.2302979 0.7697021 2 0.7135050 0.2864950 3 0.2230889 0.7769111 

EDIT

To answer your new question, you can access the positions of the support vectors in the original dataset using alphaindex(svmFit$finalModel) with coefficients coef(svmFit$finalModel) .

+6
source

Source: https://habr.com/ru/post/1493321/


All Articles