首页 > 解决方案 > Kernlab:需要 TRUE/FALSE 的缺失值?

问题描述

我想使用库中的ksvm函数执行样本分类kernlab

library(kernlab)

# PCA analysis on the first 3 component vectors
pca       <- prcomp(t(top.ranked.genes))
dat.loadings <- pca$x[, 1:3] 

# Sample classification

svp <- ksvm(dat.loadings, label, type="C-svc", scaled=T, kernel="rbfdot", kpar="automatic", prob.model=F, class.weights=NULL, fit=T, shrinking=T)

if ((type(ret) == "C-svc" || type(ret) == "nu-svc" || type(ret) == : 需要 TRUE/FALSE 的缺失值另外:警告消息: In .local(x, ...) : 强制引入的 NA

    > dput(top.ranked.genes[1:3,1:3])
    structure(c(4120.8, 1073.2, 1434.3, 3785.7, 1305.3, 1550.5, 3326.5, 
    1163.6, 1017.7), .Dim = c(3L, 3L), .Dimnames = list(c("221918_at", 
    "201554_x_at", "214722_at"), c("NB_GSM97800", "NB_GSM97803", 
    "NB_GSM97804")))

    

> dput(dat.loadings[1:3,1:3])
    structure(c(-158664.494929915, -148977.612734589, -163264.320664849, 
    -3583.353411796, -14921.765919203, -20224.318452977, 61652.7194473044, 
    18971.6967789661, 27273.153856793), .Dim = c(3L, 3L), .Dimnames = list(
        c("NB_GSM97800", "NB_GSM97803", "NB_GSM97804"), c("PC1", 
        "PC2", "PC3")))

标签: rdata-sciencesvmbioinformaticskernlab

解决方案


似乎label不是factor分类所需的。从以下文档ksvm

y可以是因子(用于分类任务)或数字向量(用于回归)。[...] 根据是否y是一个因素,类型的默认设置是C-svceps-svr

试试label <- as.factor(label)


推荐阅读