当我尝试在插入符号中训练一个简单的lm上的一些数据时,它会返回:
> rdati<-read.csv("cutDati.csv")
>
> rdati[]<-lapply(rdati, factor)
>
> dataM=as.data.frame(rdati[])
> dataM=dataM[1:100,]
>
> data=na.omit(dataM)
> trainIndex <- createDataPartition(data$d90, p = .8,
+ list = FALSE,
+ times = 1)
Warning messages:
1: In createDataPartition(data$d90, p = 0.8, list = FALSE, times = 1) :
Some classes have no records ( 4, 6, 7, 9, 10, 11, 14, 15, 16, 17, 20, 21, 22, 23, 25 ) and these will be ignored
2: In createDataPartition(data$d90, p = 0.8, list = FALSE, times = 1) :
Some classes have a single record ( 1 ) and these will be selected for the sample
> training <- data[ trainIndex,]
> testing <- data[-trainIndex,]
>
> fit <- train(d90 ~ ., data = training,
+ method = "svmLinear",
+ verbose = FALSE)
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
d90包含因子-1到27而没有0。
有人能帮助我吗? :)
谢谢, 马可
编辑:
添加一些信息
> str(training$d90)
Factor w/ 25 levels "-1","1","2","3",..: 24 2 14 4 13 6 4 4 14 6 ...
> unique(training$d90)
[1] 26 1 13 3 12 5 27 8 -1 2
Levels: -1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 20 21 22 23 25 26 27
我发现如果我限制它的工作区域。
training <- data[ trainIndex,200:300]
testing <- data[-trainIndex,200:300]
fit <- train(d90 ~ ., data = training,
method = "svmLinear",
verbose = FALSE)
我正在考虑问题在于数据,但问题可能是什么?我怎么检查?
我发现了问题,但我不明白如何解决它
我尝试了一些组合,我看到错误在第205列
> unique(training[,205])
Error in `[.data.frame`(training, , 205) :
undefined columns selected
你能帮助我吗?