Facebook
From Bugsbunny, 1 Year ago, written in R.
Embed
Download Paste or View Raw
Hits: 153
  1. library(Caret)
  2. test_index <- createDataPartition(y, times = 1, p = 0.5, list = FALSE)
  3. train_set <- data %>% slice(-test_index)
  4. test_set <- data %>% slice(test_index)
  5.  
  6. y <- factor(train_set$Churn)
  7.  
  8. control <- trainControl(method = "cv", number = 10, p = .9,  classProbs = TRUE)
  9.  
  10. train_knn <-train(y ~ ., data = data.frame(train_set), method = "knn", tuneGrid = data.frame(k= c(1,3,5,7)), trControl = control,
  11.                   preProcess = c("center", "scale"))
  12.  
  13.