插入符号包:列车功能中的分层交叉验证 [英] Caret Package: Stratified Cross Validation in Train Function

查看:82
本文介绍了插入符号包:列车功能中的分层交叉验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用训练函数将模型拟合到大型不平衡数据集时,是否可以执行分层交叉验证?我知道可以进行直接k折交叉验证,但是我的类别非常不平衡。我见过有关此主题的讨论,但没有确切的答案。

Is there a way to perform stratified cross validation when using the train function to fit a model to a large imbalanced data set? I know straight forward k fold cross validation is possible but my categories are highly unbalanced. I've seen discussion about this topic but no real definitive answer.

预先感谢。

推荐答案

有一个名为 index的参数,可以让用户指定索引进行交叉验证。

There is a parameter called 'index' which can let user specified the index to do cross validation.

folds <- 4
cvIndex <- createFolds(factor(training$Y), folds, returnTrain = T)
tc <- trainControl(index = cvIndex,
               method = 'cv', 
               number = folds)

rfFit <- train(Y ~ ., data = training, 
            method = "rf", 
            trControl = tc,
            maximize = TRUE,
            verbose = FALSE, ntree = 1000)

这篇关于插入符号包:列车功能中的分层交叉验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆