数据集:https://archive.ics.uci.edu/ml/datasets/Chess+%28King-Rook+vs.+King-Pawn%29

码:

require("e1071")

# Load the data into bank
bank <- read.csv("~/R/SVM/kr-vs-kp.data")
colnames(bank)[ncol(bank)] <- 'to.classify'
bank$to.classify <- as.factor(bank$to.classify)

# Divide the data into TRAIN and TEST sets
index <- 1:nrow(bank)
testIndex <- sample(index, trunc(length(index)/3))
testSet <- bank[testIndex,]
trainSet <- bank[-testIndex,]

# Learning sigmoid tuned nu-classification model
svm.nu.tune.model.sigmoid <- best.svm(to.classify ~ ., data = trainSet, coef0 = c(0,1,10,20,30), gamma = c(0.001, 0.003, 0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30), cost = c(1,3,10,30,100), nu = c(0.1,0.3,0.5,0.7,0.9), na.action = na.omit, kernel = 'sigmoid',  type = 'nu-classification')
print(svm.nu.tune.model.sigmoid)


错误:

Error in predict.svm(ret, xhold, decision.values = TRUE) :
  NA/NaN/Inf in foreign function call (arg 8)


该算法可以在内核和类型的任何其他组合上正常工作。这是唯一有问题的。

最佳答案

我终于弄明白了。

似乎对于给定的数据集,nu和coef0的某些值是不可行的,而不是跳过它们,而是决定丢弃整个工作并崩溃。

coef0-显然,这些值来自间隔0 <= coef0 <= 1。尽管找不到此信息。对于大于1的任何值,它只会崩溃并显示NaN / Inf错误。

nu-如果kr-vs-kp数据集的值大于0.7,则会导致“ nu不可行”错误。对于不同的较小数据集,不同的值(0 < x < 0.4)是不可行的。

我希望这可以帮助别人。

08-24 13:54