was doing LDA analysis on some dataset in ISLR library, I defined a another column as "crime", I ran analysis through glm() and ran it again using lda, however it is not finding the crime variable column which is weird because its the same train dataset I used, here is my code
Library(ISLR)
data(Boston)
Boston
nrow(Boston)
ncol(Boston)
colnames(Boston)
summary(Boston)
Boston$crime<-ifelse(Boston$crim>median(Boston$crim),1,0)
split_size=0.7
sample_size=floor(split_size*nrow(Boston))
set.seed(123)
train_indices<-sample(seq_len(nrow(Boston)),size=sample_size)
boston.train<-Boston[train_indices,]
boston.test<-Boston[-train_indices,]
summary(boston.train)
summary(boston.test)
boston.lda<-lda(crime~.,abs(-crime-crim),data=boston.train)
lda.pred<-predict(boston.lda,boston.test)
boston.train
CodePudding user response:
It can't find crime
because where lda
is expecting data
you provide it with abs(-crime-crim)
What is abs(-crime-crim)
supposed to be doing in the lda
call? If you just remove it, the call will work.
By the way, the Boston dataset is in the MASS library, not in the ISLR library.