R-k折交叉验证
来源:互联网 发布:韩国直播软件下载 编辑:程序博客网 时间:2024/04/27 18:27
training <-iris#抽样方法#ind<-sample(2,nrow(training),replace=TRUE,prob=c(0.7,0.3)) #对数据分成两部分,70%训练数据,30%检测数据nrow(training)行数#traindata<- training [ind==1,] #训练集#testdata<- training [ind==2,] #测试集10-fold cross-validation就是十折交叉验证,用来测试精度,是常用的精度测试方法。将数据集分成十分,轮流将其中9份做训练1份做测试,10次的结果的均值作为对算法精度的估计,一般还需要进行多次10倍交叉验证求均值,例如10次10倍交叉验证,更精确一点。#使用切分函数-K折交叉验证library("caret")folds<-createFolds(y=training$Species,k=10) #根据training的laber-Species把数据集切分成10等份re<-{}for(i in 1:10){traindata<-training[-folds[[i]],]testdata<-training[folds[[i]],]rf <- randomForest(Species ~ ., data=training, ntree=100, proximity=TRUE) #Species是因变量re=c(re,length(training$Species[which(predict(rf)==training$Species)])/length(training$Species))}mean(re)#取k折交叉验证结果的均值作为评判模型准确率的结果
参考其他R包自动测试
现存的方法很多都会自带现成的工具caret## Not run: ## Do 5 repeats of 10-Fold CV for the iris data. We will fit## a KNN model that evaluates 12 values of k and set the seed## at each iteration.set.seed(123)seeds <- vector(mode = "list", length = 51)for(i in 1:50) seeds[[i]] <- sample.int(1000, 22)## For the last model:seeds[[51]] <- sample.int(1000, 1)ctrl <- trainControl(method = "repeatedcv",repeats = 5,seeds = seeds)set.seed(1)mod <- train(Species ~ ., data = iris,method = "knn",tuneLength = 12,trControl = ctrl)ctrl2 <- trainControl(method = "adaptive_cv",repeats = 5,verboseIter = TRUE,seeds = seeds)set.seed(1)mod2 <- train(Species ~ ., data = iris,method = "knn",tuneLength = 12,trControl = ctrl2)
0 0
- R-k折交叉验证
- K-折交叉验证
- K折交叉验证
- k折交叉验证
- k-折交叉验证
- K折交叉验证
- K折交叉验证-python
- K-折交叉验证算法
- k-折交叉验证(k-fold CrossValidation)
- k-折交叉验证(k-fold CrossValidation)
- k-折交叉验证(k-fold crossValidation)
- k-折交叉验证(k-fold crossValidation)
- k-折交叉验证(k-fold crossValidation)
- K-折交叉验证(k-fold crossValidation)
- k-折交叉验证,留一验证
- r语言n折交叉验证
- k折交叉验证;k-fold交叉验证;k-fold cross-validation
- 交叉验证(简单交叉验证、k折交叉验证、留一法)
- 机器学习(1)之梯度下降(gradient descent)
- phpstorm10激活方法
- How to Install Subversion (SVN) 1.8.15 on CentOS/RHEL 7/6/5
- Mysql --分区表的管理与维护
- android开发时建立xml文件后在类中通过R.layout找不到相应的xml文件的解决方法
- R-k折交叉验证
- zookeeper 入门讲解实例 转
- *_train_test.prototxt,*_deploy.prototxt,*_slover.prototxt文件编写时注意事项
- zendstudio 13.0
- 常用网站
- ListView的动态刷新问题——用notifyDataSetChanged没作用
- 移动端开发-数据分析
- HDOJ 1513 LCS + 滚动数组
- 逆序数