【问题标题】:SVM:Need numeric dependent variable for regressionSVM:需要用于回归的数字因变量
【发布时间】:2017-04-19 15:17:07
【问题描述】:

我有以下数据

scorer<-function(points){
        points["scores"] <- as.vector((points$X-5)^2+(points$Y-5)^2-9)
        points["class"]<-(as.vector(  points$scores<0 ))
        points
}
dt<-scorer(data.frame(X=c(0,1,5,20,5,3,9,3,5,5),Y=c(0,9,9,0,-18,3,4,5,7,4)))

然后我尝试使用 SVM 预测最后一列(类)

library(e1071)
model <- svm(class ~ . , dt)
predictedClass <- predict(model, dt)

但它抱怨:

Error in svm.default(x, y, scale = scale, ..., na.action = na.action) : 
  Need numeric dependent variable for regression.

【问题讨论】:

  • 尝试指定您希望分类而不是回归:model &lt;- svm(class ~ . , dt, type = "C").

标签: r


【解决方案1】:

nya建议确实有效。

请看type参数说明

svm 可以用作分类机、回归机或 新奇检测。取决于 y 是否是一个因子,默认设置 对于类型是 C-classificationeps-regression ... page 50

【讨论】:

    【解决方案2】:

    使用您的数据集,您可以使用 svm 方法进行分类。

    但是,如果您绝对想进行回归,请尝试将变量“类”转换为数字形式,该值可以取值为 1 表示负分,0 表示正分。

    function(points) {
    
    points["scores"] <- as.vector((points$X-5)^2+(points$Y-5)^2-9)
                       points["class"]<-as.vector(  ifelse(points$scores<0 ,1,0))
                       points
                     }
    dt<-scorer(data.frame(X=c(0,1,`enter code here`5,20,5,3,9,3,5,5),Y=c(0,9,9,0,-18,3,4,5,7,4)))
    svm(class~.,dt)
    

    【讨论】:

    猜你喜欢
    • 2011-05-26
    • 2011-12-22
    • 2015-03-30
    • 2018-08-18
    • 2022-01-15
    • 1970-01-01
    • 2017-08-27
    • 2023-03-18
    • 2015-06-30
    相关资源
    最近更新 更多