I am new to machine learning. I am having trouble in lda function in r.
Below is my code
library(MASS)
folds <- createFolds(ForwardPlayers$Rating, k = 10)
cv_lda <- lapply(folds, function(x) { # start of function
# in the next two lines we will separate the Training set into it's 10 pieces
training_fold = ForwardPlayers[-x, ] # training fold = training set minus (-) it's sub test fold
print(training_fold)
test_fold = ForwardPlayers[x, ] # here we describe the test fold individually
# now apply (train) the classifer on the training_fold
classifier = lda(Rating ~ .,training_fold)
# next step in the loop, we calculate the predictions and cm and we equate the accuracy
# note we are training on training_fold and testing its accuracy on the test_fold
y_pred = predict(classifier, newdata = test_fold[-1])
length(test_fold[,1])
length(y_pred)
cm = table(test_fold$Rating, y_pred$class)
accuracy <- sum(diag(cm))/sum(cm)
return(accuracy)
})
accuracy_lda <- mean(as.numeric(cv_lda))
It gives me following error.
Warning message:
In lda.default(x, grouping, ...) : group 1 is empty
Thank you in advance!!