Why is the confusion matrix and test error the same despite the LDA being done different datasets

49 views Asked by At
library(ISLR2)
df = Auto
df$mclass <- as.factor(ifelse(df$mpg <20, 'low', ifelse(df$mpg >= 20  & df$mpg < 27, 'medium', 'high')))

I have split the dataset into test and training

test = df[df$year == 75,]
test.direction = test$mclass
training =  df[df$year !=  75,]
training.direction = training$mclass

I have done LDA on entire dataset

lda1 = lda(mclass ~ acceleration + displacement + horsepower +  weight, df)

ive used only the test dataset to test prediction

table (predict(lda1,test)$class, test.direction)

Ive then redone LDA using just the training data set (everything not in test data set)

lda2 = lda(mclass ~ acceleration + displacement + horsepower +  weight, data = training)

and redone the prediction on test data

table (predict(lda2,test)$class,test.direction)

The results of both predictions are the same - even though the LDA have been done different datasets - I would expect that they would be different?

0

There are 0 answers