gpt4 book ai didi

r - 支持向量机 :Need numeric dependent variable for regression

转载 作者:行者123 更新时间:2023-12-05 02:19:07 26 4
gpt4 key购买 nike

我有以下数据

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.

最佳答案

来自 nya建议真的有效。

请看类型参数说明

svm can be used as a classification machine, as a regression machine, or for novelty detection. Depending on whether y is a factor or not, the default setting for type is C-classification or eps-regression ... page 50

关于r - 支持向量机 :Need numeric dependent variable for regression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43499772/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com