详解R语言caret包trainControl函数_第1页
详解R语言caret包trainControl函数_第2页
详解R语言caret包trainControl函数_第3页
详解R语言caret包trainControl函数_第4页
详解R语言caret包trainControl函数_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第详解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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论