1
我一直在使用kernlab
软件包,并且使用ksvm
/predict
函数和预计算内核来解决问题。使用带预计算内核的kernlab软件包时出错
我已经得到该错误消息:
> ksvm.mod <- ksvm(trainingset.outer, traininglabels.outer, kernel = "matrix",type="C-svc", C = 60, prob.model = TRUE)
> temp <- predict(ksvm.mod, test.kernel.outer)
Error in .local(object, ...) : test vector does not match model !
我已经看过了错误的地点的源代码,发现它是由于在列
newnrows <- nrow(newdata)
newncols <- ncol(newdata)
if(!is(newdata,"kernelMatrix") && !is.null(xmatrix(object))){
if(is(xmatrix(object),"list") && is(xmatrix(object)[[1]],"matrix")) oldco <- ncol(xmatrix(object)[[1]])
if(is(xmatrix(object),"matrix")) oldco <- ncol(xmatrix(object))
if (oldco != newncols) stop ("test vector does not match model !")
}
差异然而,我已经使用的对象有相同的列
> ncol(trainingset.outer)
[1] 1498
> ncol(test.kernel.outer)
[1] 1498
然后,我看了看co根据模型存储的列,发现如下:
> ncol(xmatrix(ksvm.mod)[[1]])
Error in xmatrix(ksvm.mod)[[1]] : subscript out of bounds
> xmatrix(ksvm.mod)[[1]]
Error in xmatrix(ksvm.mod)[[1]] : subscript out of bounds
> xmatrix(ksvm.mod)
<0 x 0 matrix>
> ?xmatrix
> ksvm.mod
Support Vector Machine object of class "ksvm"
SV type: C-svc (classification)
parameter : cost C = 60
[1] " Kernel matrix used as input."
Number of Support Vectors : 831
Objective Function Value : -211534.1
Training error : 0.257677
Probability model included.
> ncol(xmatrix(gene)[[1]]) # for dataframes used without precomputed kernels
[1] 172
我想模型没有存储任何对象,我的理解是否正确?由于在web上使用预计算内核的软件包没有很好的例子,我正在写信给你。 PS:我会尝试提供测试数据,如果需要的话。