版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第详解R语言caret包trainControl函数目录trainControl参数详解源码参数详解示例
trainControl参数详解
源码
caret::trainControl-
function(method="boot",number=ifelse(grepl("cv",method),10,25),repeats=ifelse(grepl("[d_]cv$",method),1,NA),p=0.75,search="grid",initialWindow=NULL,horizon=1,fixedWindow=TRUE,skip=0,verboseIter=FALSE,returnData=TRUE,returnResamp="final",savePredictions=FALSE,
classProbs=FALSE,summaryFunction=defaultSummary,selectionFunction="best",
preProcOptions=list(thresh=0.95,ICAcomp=3,k=5,
freqCut=95/5,uniqueCut=10,cutoff=0.9),sampling=NULL,
index=NULL,indexOut=NULL,indexFinal=NULL,timingSamps=0,
predictionBounds=rep(FALSE,2),seeds=NA,adaptive=list(min=5,
alpha=0.05,method="gls",complete=TRUE),
trim=FALSE,allowParallel=TRUE)
if(is.null(selectionFunction))
stop("nullselectionFunctionvaluesnotallowed")
if(!(returnResamp%in%c("all","final","none")))
stop("incorrectvalueofreturnResamp")
if(length(predictionBounds)0length(predictionBounds)!=
stop("'predictionBounds'shouldbealogicalornumericvectoroflength2")
if(any(names(preProcOptions)=="method"))
stop("'method'cannotbespecifiedhere")
if(any(names(preProcOptions)=="x"))
stop("'x'cannotbespecifiedhere")
if(!is.na(repeats)!(method%in%c("repeatedcv",
"adaptive_cv")))
warning("`repeats`hasnomeaningforthisresamplingmethod.",
call.=FALSE)
if(!(adaptive$method%in%c("gls","BT")))
stop("incorrectvalueofadaptive$method")
if(adaptive$alpha1e-07|adaptive$alpha1)
stop("incorrectvalueofadaptive$alpha")
if(grepl("adapt",method)){
num-if(method=="adaptive_cv")
number*repeats
elsenumber
if(adaptive$min=num)
stop(paste("adaptive$minshouldbelessthan",
num))
if(adaptive$min=1)
stop("adaptive$minshouldbegreaterthan1")
if(!(search%in%c("grid","random")))
stop("`search`shouldbeeither'grid'or'random'")
if(method=="oob"any(names(match.call())=="summaryFunction")){
warning("Customsummarymeasurescannotbecomputedforout-of-bagresampling.",
"Thisvalueof`summaryFunction`willbeignored.",
call.=FALSE)
list(method=method,number=number,repeats=repeats,
search=search,p=p,initialWindow=initialWindow,
horizon=horizon,fixedWindow=fixedWindow,skip=skip,
verboseIter=verboseIter,returnData=returnData,returnResamp=returnResamp,
savePredictions=savePredictions,classProbs=classProbs,
summaryFunction=summaryFunction,selectionFunction=selectionFunction,
preProcOptions=preProcOptions,sampling=sampling,
index=index,indexOut=indexOut,indexFinal=indexFinal,
timingSamps=timingSamps,predictionBounds=predictionBounds,
seeds=seeds,adaptive=adaptive,trim=trim,allowParallel=allowParallel)
参数详解
trainControl所有参数详解method重抽样方法:Bootstrap(有放回随机抽样)、Bootstrap632(有放回随机抽样扩展)、LOOCV(留一交叉验证)、LGOCV(蒙特卡罗交叉验证)、cv(k折交叉验证)、repeatedcv(重复的k折交叉验证)、optimism_boot(Efron,B.,Tibshirani,R.J.(1994).Anintroductiontothebootstrap,pages249-252.CRCpress.)、none(仅使用一个训练集拟合模型)、oob(袋外估计:随机森林、多元自适应回归样条、树模型、灵活判别分析、条件树)number控制K折交叉验证的数目或者Bootstrap和LGOCV的抽样迭代次数repeats控制重复交叉验证的次数pLGOCV:控制训练比例verboseIter输出训练日志的逻辑变量returnData逻辑变量,把数据保存到trainingData中(str(trainControl)查看)searchsearch=grid(网格搜索),random(随机搜索)returnResamp包含以下值的字符串:final、all、none,设定有多少抽样性能度量被保存。classProbs是否计算类别概率summaryFunction根据重抽样计算模型性能的函数selectionFunction选择最优参数的函数index指定重抽样样本(使用相同的重抽样样本评估不同的算法、模型)allowParallel是否允许并行
示例
library(mlbench)#使用包中的数据
Warningmessage:
程辑包‘mlbench'是用R版本4.1.3来建造的
data(Sonar)
str(Sonar[,1:10])
'data.frame':208obs.of10variables:
$V1:num0.020.04530.02620.010.07620.02860.03170.05190.02230.0164...
$V2:num0.03710.05230.05820.01710.06660.04530.09560.05480.03750.0173...
$V3:num0.04280.08430.10990.06230.0481...
$V4:num0.02070.06890.10830.02050.0394...
$V5:num0.09540.11830.09740.02050.059...
$V6:num0.09860.25830.2280.03680.0649...
$V7:num0.1540.2160.2430.110.121...
$V8:num0.160.3480.3770.1280.247...
$V9:num0.31090.33370.55980.05980.3564...
$V10:num0.2110.2870.6190.1260.446...
数据分割:
library(caret)
set.seed(998)
inTraining-createDataPartition(Sonar$Class,p=.75,list=FALSE)
training-Sonar[inTraining,]#训练集
testing-Sonar[-inTraining,]#测试集
模型拟合:
fitControl-trainControl(##10折交叉验证
method="repeatedcv",
number=10,
##重复10次
repeats=1)
set.seed(825)
gbmFit1-train(Class~.,data=training,
method="gbm",#助推树
trControl=fitControl,
verbose=FALSE)
gbmFit1
StochasticGradientBoosting
157samples
60predictor
2classes:'M','R'
Nopre-processing
Resampling:Cross-Validated(10fold,repeated10times)
Summaryofsamplesizes:141,142,141,142,141,142,...
Resamplingresultsacrosstuningparameters:
interaction.depthn.treesAccuracyKappa
1500.79357840.5797839
11000.81710780.6290208
11500.82196080.6383173
2500.80419120.6027771
21000.82961760.6544713
21500.82836270.6520251
3500.81103430.6170317
31000.83012750.6551379
31500.83103430.6577252
Tuningparameter'shrinkage'washeld
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026中国食品饮料包装行业产品创新市场需求品牌竞争市场潜力分析
- 2026汽车美容行业消费需求分析及产业规模规划研究报告
- 2026中国植物蛋白饮料行业市场竞争格局与品牌建设策略报告
- 2026中国新能源汽车行业政策支持与市场拓展策略评估报告
- 2026中国医药研发行业供需分析及投资评估规划分析研究报告
- 2026汽车自动驾驶传感器系统开发方案研究
- 2026食品加工设备行业技术创新与产能升级研究研究报告
- 2026人工智能零售行业现状需求供给分析投资评估规划行业发展趋势
- 2026杂志封面面试题及答案
- 2026招教幼儿面试题目及答案
- 2025年中考数学一轮复习知识清单专题12 多边形与平行四边形(2大模块知识梳理+10个考点+2个重难点+1个易错点)(原卷版)
- 《贝聿铭建筑设计解析》课件
- 2024风电工程项目划分详表
- 北师大八年级数学上册位置与坐标《确定位置》示范公开课教学课件
- 《简爱》阅读任务单三
- 钢结构施工组织设计【超完美版】
- 自然辩证法学习通超星期末考试答案章节答案2024年
- 衢州离婚协议书范文2023标准版
- 职业技术学校云计算技术应用专业《岗位实习》课程标准
- AQ/T 2056-2016 金属非金属矿山在用空气压缩机安全检验规范 第2部分:移动式空气压缩机(正式版)
- 舞台化妆计划书
评论
0/150
提交评论