我在
我的问题是:一个人如何使用
我提出这些参数是因为我希望RF使用符合我的数据中正负比例的Bootstrap样本。
这个其他讨论串开始了关于这个主题的讨论,但最终没有澄清如何使用这些参数。
randomForest
的文档中读到以下内容:
参考函数接口如下:strata:用于分层抽样的(因子)变量。
sampsize:要绘制的样本大小。对于分类问题,如果sampsize是与分层数相同长度的向量,则按分层进行分层抽样,并且sampsize的元素指示从分层中绘制的数量。
randomForest(x, y=NULL, xtest=NULL, ytest=NULL, ntree=500,
mtry=if (!is.null(y) && !is.factor(y))
max(floor(ncol(x)/3), 1) else floor(sqrt(ncol(x))),
replace=TRUE, classwt=NULL, cutoff, strata,
sampsize = if (replace) nrow(x) else ceiling(.632*nrow(x)),
nodesize = if (!is.null(y) && !is.factor(y)) 5 else 1,
maxnodes = NULL,
importance=FALSE, localImp=FALSE, nPerm=1,
proximity, oob.prox=proximity,
norm.votes=TRUE, do.trace=FALSE,
keep.forest=!is.null(y) && is.null(xtest), corr.bias=FALSE,
keep.inbag=FALSE, ...)
我的问题是:一个人如何使用
strata
和sampsize
?这里有一个最小化的工作示例,我想测试这些参数:library(randomForest)
iris = read.table("http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data", sep = ",", header = FALSE)
names(iris) = c("sepal.length", "sepal.width", "petal.length", "petal.width", "iris.type")
model = randomForest(iris.type ~ sepal.length + sepal.width, data = iris)
> model
500 samples
6 predictors
2 classes: 'Y0', 'Y1'
No pre-processing
Resampling: Bootstrap (7 reps)
Summary of sample sizes: 477, 477, 477, 477, 477, 477, ...
Resampling results across tuning parameters:
mtry ROC Sens Spec ROC SD Sens SD Spec SD
2 0.763 1 0 0.156 0 0
4 0.782 1 0 0.231 0 0
6 0.847 1 0 0.173 0 0
ROC was used to select the optimal model using the largest value.
The final value used for the model was mtry = 6.
我提出这些参数是因为我希望RF使用符合我的数据中正负比例的Bootstrap样本。
这个其他讨论串开始了关于这个主题的讨论,但最终没有澄清如何使用这些参数。
?randomForest
中展示分层抽样的示例代码不够清晰吗? - joransampsize
而不是strata
。文档仅说明:“strata
:用于分层抽样的(因子)变量”。在这种情况下,“使用”一词对我来说不太清楚,可能是因为我对分层抽样和R相对较新。 - Amelio Vazquez-Reina