I am trying to solve the well-known problem named
Titanic- Machine Learning from Disaster.
I want to apply
knn to predict the
survived from the test dataset. I also want to use
cross-validation and then want to apply it to my test dataset.
The code structure is given below:
install.packages("caret") library(caret) knn_2_train <- knn_1_train # train dataset knn_2_train$Survived <- train$Survived Survived <- as.factor(train$Survived) # train labels knn_2_test <- knn_1_test # test dataset trControl <- trainControl(method = "cv", number = 5) fit <- train(knn_2_train, Survived, method = "knn", tuneGrid = expand.grid(k = 1:50), metric = "Accuracy", trControl = trControl )
Now, I am not sure how can I apply the
knn model for the test dataset after the
Any kind of suggestion is appreciable.