我正在使用一个大约有 150000 行和 25 列的数据集。数据由数值变量和因子变量组成。因子变量既是文本又是数字,我需要它们。因变量是一个有 20 个水平的因子。我正在尝试使用kernlab
R 中的包构建模型并将其输入到 SVM 中。
library(kernlab)
n<- nrow(x)
trainInd<- sort(sample(1:nrow(x), n*.8))
xtrain<- x[trainInd,]
xtest<- x[-trainInd,]
ytrain<- y[trainInd]
ytest<- y[-trainInd]
modelclass<- ksvm(x=as.matrix(xtrain), y=as.matrix(ytrain),
scaled = TRUE, type="C-svc", kernel = "rbfdot",
kpar="automatic", C=1, cross=0)
按照代码,我收到此错误:
Error in if (any(co)) { : missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In FUN(newX[, i], ...) : NAs introduced by coercion
xtrain
数据框如下所示:
Length Gender Age Day Hour Duration Period
5 1 80 5 11 20 3
0.2 2 35 2 18 10 5
1.1 2 55 1 15 120 4
Gender、Day 和 Period 变量是分类变量(因子),其余变量是数字变量。
我经历了类似的问题,也经历了我的数据集,但我无法识别任何 NA 值或其他错误。
我假设我在变量类型上做错了什么,特别是因素。我不确定如何使用它们,但我看不出有什么问题。任何有关如何解决错误以及可能如何将因子与数值变量一起建模的帮助将不胜感激。