のドキュメントで次のことを読みましたrandomForest
。
階層: 階層化サンプリングに使用される (因子) 変数。
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, ...)
私の質問は次のとおりです。どのように正確に and を使用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 に、データのポジティブとネガティブの比率を考慮したブートストラップ サンプルを使用してもらいたいからです。
この別のスレッドは、トピックに関する議論を開始しましたが、これらのパラメーターをどのように使用するかを明確にすることなく解決されました.