support vector machine train caret error kernlab class probability calculations failed; returning NAs

纵然是瞬间 提交于 2019-12-04 07:02:41

In the train control statement, you have to specify if you want the class probabilities classProbs = TRUE returned.

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")

giving the probabilities of being in the Bad or Good class in the test dataset as:

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 position of the support vectors in your original data set with alphaindex(svmFit$finalModel) with coefficients coef(svmFit$finalModel).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!