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:我會嘗試提供測試數據,如果需要的話。