【问题标题】:R | NA/NaN/Inf in foreign function call | e1071 SVM右 |外函数调用中的 NA/NaN/Inf | e1071 支持向量机
【发布时间】:2015-09-10 11:57:47
【问题描述】:

数据集: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)

该算法适用于内核和类型的任何其他组合。这是唯一有问题的。

【问题讨论】:

    标签: r machine-learning svm libsvm


    【解决方案1】:

    我终于明白了。

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

    coef0 - 显然这些值来自区间 0 &lt;= coef0 &lt;= 1。虽然这个信息无处可寻。对于大于 1 的任何东西,它都会因 NaN/Inf 错误而崩溃。

    nu - 对于大于 0.7 的 kr-vs-kp 数据集,它会导致“nu infeasible”错误。对于不同的较小数据集,不同的值 (0 &lt; x &lt; 0.4) 是不可行的。

    我希望这对某人有所帮助。

    【讨论】:

      【解决方案2】:

      问题似乎是您在同一个调用中混合了参数。如果您只是将 nu 参数与 nu-classification 一起使用(并且在另一个调用中将 cost 参数与 C-classification 一起使用),那么它应该可以工作。

      例如:

      svm.nu.tune.model.sigmoid <- best.svm(to.classify ~ ., data = trainSet, nu = c(0.1,0.3,0.5,0.7,0.9), na.action = na.omit, kernel = 'sigmoid',  type = 'nu-classification')
      

      【讨论】:

      • 其他 nu 分类器在包含成本参数方面没有任何问题,尽管我承认我忘记删除它。我删除它并重新运行代码,但问题仍然存在。 svm.nu.tune.model.sigmoid &lt;- 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), nu = c(0.1,0.3,0.5,0.7,0.9), na.action = na.omit, kernel = 'sigmoid', type = 'nu-classification')
      猜你喜欢
      • 2014-03-28
      • 1970-01-01
      • 1970-01-01
      • 2012-09-05
      • 2013-10-24
      • 2019-10-10
      • 2014-03-18
      • 2018-07-03
      • 2016-07-24
      相关资源
      最近更新 更多