raero-glass

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


I'm trying to solve this problem from few days but google can't help :( I got Error like that:

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

At stack were simillar topic: R Error : some group is too small for 'qda'

But I cant find out how to do that : /

This is my code:

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)

Everything is great but next lines..

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

Hope, help will came soon!


Solution

  • It's not wrong code (there is little mistake), when this error show

    some group is too small for 'qda'

    Tt means that the dataSet is wrong. To repair that you should modify dataSet.