我有这个问题而且我不明白为什么会这样。我检查了很多帖子并尝试了许多解决方案,例如unlist
但是,它似乎并不想工作..
由于它是作业,我删除了一些部分,但我让主要部分:
my_svm <- function(df, alpha, degree, cost)
{
mylist = partition(df, alpha)
df1 = mylist[[1]]
df2 = mylist[[2]]
...
lastColName <- colnames(df)[ncol(df)]
...
model <- svm(as.formula(paste(lastColName, "~ .", sep = " ")),
data = df1,
kernel="polynomial",
degree = degree,
type = "C-classification",
cost = cost)
a = confusionMatrix(df1[,-ncol(df1)], model)
...
}
然而,它一直说Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
为什么呢?如果我使用unlist
或正确的名称,它会继续发生......我真的不明白为什么......
提前感谢您的任何帮助
`List of 2
$ :'data.frame': 1382 obs. of 7 variables:
..$ buying : Factor w/ 4 levels "high","low","med",..: 4 1 2 4 4 2 4 3 3 2 ...
..$ maint : Factor w/ 4 levels "high","low","med",..: 2 2 3 1 4 4 4 3 4 4 ...
..$ doors : Factor w/ 4 levels "2","3","4","5more": 2 3 1 1 1 2 4 3 3 3 ...
..$ persons : Factor w/ 3 levels "2","4","more": 2 2 1 2 3 3 3 3 3 1 ...
..$ lug_boot: Factor w/ 3 levels "big","med","small": 3 3 3 2 1 2 2 1 2 3 ...
..$ safety : Factor w/ 3 levels "high","low","med": 3 3 1 3 3 1 1 1 1 1 ...
..$ class : Factor w/ 4 levels "acc","good","unacc",..: 3 3 3 3 3 1 3 4 1 3 ...
$ :'data.frame': 346 obs. of 7 variables:
.. $ buying : Factor w/ 4 levels "high","low","med",..: 4 4 4 4 4 4 4 4 4 4 ...
.. $ maint : Factor w/ 4 levels "high","low","med",..: 4 4 4 4 4 4 4 4 4 4 ...
.. $ doors : Factor w/ 4 levels "2","3","4","5more": 1 1 1 1 1 2 2 2 2 3 ...
.. $ persons : Factor w/ 3 levels "2","4","more": 1 1 2 2 3 2 2 2 3 1 ...
.. $ lug_boot: Factor w/ 3 levels "big","med","small": 2 1 3 1 2 3 3 3 3 3 ...
.. $ safety : Factor w/ 3 levels "high","low","med": 3 2 3 3 3 2 3 1 3 1 ...
.. $ class : Factor w/ 4 levels "acc","good","unacc",..: 3 3 3 3 3 3 3 3 3 3 ...`
List of 30
$ call : language svm(formula = as.formula(paste(lastColName, "~ .", sep = " ")), data = df1, kernel = "polynomial", degree = degree, type = "C-classification", cost = cost)
$ type : num 0
$ kernel : num 1
$ cost : num 0.1
$ degree : num 1
$ gamma : num 0.0625
$ coef0 : num 0
$ nu : num 0.5
$ epsilon : num 0.1
$ sparse : logi FALSE
$ scaled : logi [1:16] FALSE FALSE FALSE FALSE FALSE FALSE ...
$ x.scale : NULL
$ y.scale : NULL
$ nclasses : int 4
$ levels : chr [1:4] "acc" "good" "unacc" "vgood"
$ tot.nSV : int 731
$ nSV : int [1:4] 308 315 47 61
$ labels : int [1:4] 1 3 4 2
$ SV : num [1:731, 1:16] 0 0 0 0 0 0 0 0 1 0 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:731] "368" "1478" "1067" "1049" ...
.. ..$ : chr [1:16] "buyinghigh" "buyinglow" "buyingmed" "buyingvhigh" ...
$ index : int [1:731] 1 6 7 17 22 35 36 38 40 44 ...
$ rho : num [1:6] 1.04 -1.02 -1.03 -1.03 -1.08 ...
$ compprob : logi FALSE
$ probA : NULL
$ probB : NULL
$ sigma : NULL
$ coefs : num [1:731, 1:3] 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 ...
$ na.action : NULL
$ fitted : Factor w/ 4 levels "acc","good","unacc",..: 3 3 3 3 3 3 3 3 3 3 ...
..- attr(*, "names")= chr [1:1382] "368" "382" "577" "13" ...
$ decision.values: num [1:1382, 1:6] -0.86 -1.398 -1.101 -1.274 -0.916 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:1382] "368" "382" "577" "13" ...
.. ..$ : chr [1:6] "acc/unacc" "acc/vgood" "acc/good" "unacc/vgood" ...
$ terms :Classes 'terms', 'formula' language class ~ buying + maint + doors + persons + lug_boot + safety
.. ..- attr(*, "variables")= language list(class, buying, maint, doors, persons, lug_boot, safety)
.. ..- attr(*, "factors")= int [1:7, 1:6] 0 1 0 0 0 0 0 0 0 1 ...
.. .. ..- attr(*, "dimnames")=List of 2
.. .. .. ..$ : chr [1:7] "class" "buying" "maint" "doors" ...
.. .. .. ..$ : chr [1:6] "buying" "maint" "doors" "persons" ...
.. ..- attr(*, "term.labels")= chr [1:6] "buying" "maint" "doors" "persons" ...
.. ..- attr(*, "order")= int [1:6] 1 1 1 1 1 1
.. ..- attr(*, "intercept")= num 0
.. ..- attr(*, "response")= int 1
.. ..- attr(*, ".Environment")=<environment: 0x0000000019274010>
.. ..- attr(*, "predvars")= language list(class, buying, maint, doors, persons, lug_boot, safety)
.. ..- attr(*, "dataClasses")= Named chr [1:7] "factor" "factor" "factor" "factor" ...
.. .. ..- attr(*, "names")= chr [1:7] "class" "buying" "maint" "doors" ...
- attr(*, "class")= chr [1:2] "svm.formula" "svm"