##KNN-qc-ml
加载数据和包
rm(list=ls())
library(pROC)
library(ggplot2)
library(dplyr) #mutate依赖环境
library(magrittr) #%>%依赖
library(e1071)
library(caret)
library(RSNNS)
library(neuralnet) # 导入所需的库
setwd("D:/Data")
data<- read.csv("ml.csv", header = T)
#划分数据集
set.seed(1898)
set.seed(123)
trainIndex <- createDataPartition(data$Groups, p = 0.7, list = FALSE)
train <- data[trainIndex, ]
test <- data[-trainIndex, ]
trcl <- trainControl(method=“cv”, number=10) #5重交叉验证
trgrid <- expand.grid(k=seq(1,10,1))
KNN<- train(Groups~.,data,
method=“knn”,
trControl = trcl,
tuneGrid=trgri