我想将kernlab软件包中的KSVM用于具有加权类(或不平衡类)的R,但是该函数无法识别向量并引发.local(x, ...)
错误。
我创建了一个命名向量,用于复制和粘贴数据类别的数据变量TRAIN的级别(z =“负”,“正”,“不确定”),然后按写成的方式将此向量提供给ksvm功能手册(即使没有示例进行不平衡分析)。但是,我得到了一个拼写错误。 我也尝试直接在帖子(Class Weight Syntax in Kernlab?)中给出的函数中给出向量,但是给出了相同的错误。 然后我试图给每堂课一个费用,这也没有用。
>
# define named vector
> VECT = c(1.0, 0.5, 0.7)
> names(VECT) = c("negative", "positive", "uncertain")
> VECT
negative positive uncertain
1.0 0.5 0.7
# show levels of dataframe
> unique(TRAIN$z)
[1] negative positive uncertain
Levels: negative positive uncertain
# run model with named vector
> mod = ksvm(z ~ a+b, data = TRAIN,
+ type = "C-svc",
+ kernel = "rbfdot",
+ kpar = "automatic",
+ C = 1,
+ prob.model = TRUE,
+ class.weights = VECT
+ )
Error in .local(x, ...) :
At least one level name is missing or misspelled.
# second approach
> mod = ksvm(cons ~ mr+fcn, data = TRAIN,
+ type = "C-svc",
+ kernel = "rbfdot",
+ kpar = "automatic",
+ C = 1,
+ prob.model = TRUE,
+ class.weights = c("negative" = 0.5,
+ "positive" = 1,
+ "uncertain" = 0.7)
+ )
Error in .local(x, ...) :
At least one level name is missing or misspelled.
# third approach
> VECT = c(1, 10, 5)
> names(VECT) = c("negative", "positive", "uncertain")
> VECT
negative positive uncertain
1 10 5
> mod = ksvm(cons ~ mr+fcn, data = TRAIN,
+ type = "C-svc",
+ kernel = "rbfdot",
+ kpar = "automatic",
+ C = c(0.5, 1, 0.7),
+ prob.model = TRUE,
+ class.weights = VECT
+ )
Error in .local(x, ...) :
At least one level name is missing or misspelled.
因此,我期望有一个完整的模型,而不是Error in .local(x, ...) :
At least one level name is missing or misspelled
。
因为变量z只有三个值,所以我将它们粘贴到 VECT,这怎么可能是拼写错误?
如何正确地进行不平衡的SVM分析?
谢谢