'QDA and LDA returning NA mean in R

I have been learning LDA and QDA for predicting models in R, I picked up ISLR book and tried working on some problems, I used the Auto.csv dataset and wanted to run a model using LDA and QDA

here is my code, I get a NA value for mean and whenever I run the predict() function I get this warning message

auto.qda.pred<-predict(auto.qda,auto.test)
Warning message:
In FUN(newX[, i], ...) : no non-missing arguments to min; returning Inf
> auto.qda.pred
  

#Here is my code for the whole process, sorry if its too long 
Auto<-read.csv(file.choose(),header=TRUE)
auto<-na.omit(Auto)
attach(auto)
colnames(auto)[1]<-'Mpg'
library('GGally')
auto$mpg01<-ifelse(auto$Mpg>median(auto$Mpg),1,0)
auto$mpg01<-as.factor(auto$mpg01)
auto$horsepower<-as.numeric(auto$horsepower)
str(auto)
summary(auto)
#mpg highly correlated with mpg01, but not with other variables like horsepower, weight etc..
split_size=0.7
sample_size=floor(split_size*nrow(auto))
set.seed(123)
train_indices<-sample(seq_len(nrow(auto)),size=sample_size)
train_indices
auto.train<-auto[train_indices,]
auto.test<-auto[-train_indices,]
nrow(auto.train)
nrow(auto.test)
library('MASS')
library('caret')
auto.lda<-lda(mpg01~cylinders+displacement+horsepower+weight,data=auto.train)
auto.pred=predict(auto.lda,auto.test)
na.omit(auto.pred)
auto.test
auto.pred$class
mean(auto.pred$class!=auto.test$mpg01)

set.seed(123)
auto.qda<-qda(mpg01~cylinders+displacement+horsepower+weight,data=auto.train)
auto.qda
auto.qda.pred<-predict(auto.qda,auto.test)
na.omit(auto.qda.pred)
mean(auto.qda.pred$class!=auto.test$mpg01)
[1] NA



 
    


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source