R - 某些组的错误对于 'qda' 来说太小了

R - Error some group is too small for 'qda'

几天来我一直在尝试解决这个问题,但google无能为力:( 我得到了这样的错误:

Error in qda.default(x, grouping, ...) : some group is too small for 'qda'

堆栈中有类似的主题: R Error : some group is too small for 'qda'

但我不知道该怎么做:/

这是我的代码:

library(MASS)
library(mlbench)
library(caret)
library(class)
data(Glass)
Glass <- data.frame(Glass)
Glass <- na.omit(Glass)

Glass$Type = as.factor(Glass$Type)
x = as.matrix(Glass[,names(Glass) != "Type"])
mode(x) = "numeric"
Glass[,names(Glass) != "Type"] <-x
ind <- sample(2, nrow(Glass), replace = TRUE, prob=c(0.8, 0.2))
train <- Glass[ind == 1,]
test <- Glass[ind == 2,]
train[,names(Glass) != "Type"] <- apply(train[,names(Glass) != "Type"], 2, jitter)

一切都很好,但下一行..

qda_Typeifier <- qda(Type~ ., data=train)
ypred.test <- predict(qda_Typeifier,test)$Type
mean(ypred.test == test$Type)

希望,帮助很快就会到来!

不是代码错误(很少有错误),当这个错误显示时

some group is too small for 'qda'

Tt表示dataSet错误。 要修复您应该修改数据集。