r - 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")))
解决方案
似乎label
不是factor
分类所需的。从以下文档ksvm
:
y
可以是因子(用于分类任务)或数字向量(用于回归)。[...] 根据是否y
是一个因素,类型的默认设置是C-svc
或eps-svr
。
试试label <- as.factor(label)
。
推荐阅读
- javascript - 执行 put 请求时,Req.body 为空对象
- react-native - 我如何获得这个 ES6 Class 的道具?
- html - 更改 src 属性时防止 iframe 重新加载?
- python - 在 Python 的数据框中将日期列转换为 MM/DD/YYYY 格式
- java - 没有互联网连接时显示刷新页面按钮
- python - 项目之前出现在列表中的次数
- windows - 显示(Surface Pro 4)在使用 Eclipse 之后/期间闪烁
- c++ - 如何优化代码以返回最接近给定整数的数字,而不存在于给定列表中?
- tensorflow - 在分类 AI 问题中训练非活动类
- r - 分组时保留列