タイタニック データ セットの生存/死亡を予測するためにCARET
およびパッケージを使用したいと考えています。nnet
それぞれに 1 つの隠しノード、2 つの隠しノード、... 20 の隠しノードを持つ 20 個のニューラル ネットワークを適合させたいと考えています。通常、CARET
パッケージはトレーニング データに基づいて最適なモデルを選択しますが、20 個のネットワークのそれぞれを取得して、それぞれをテスト データに適用したいと考えています。テスト データ セットに対してテストするために、各モデルを保存するにはどうすればよいですか? CARET パッケージに役立つ方法はありますか?
1 に答える
3
直接ではありませんが、可能なはずです。fit
それらをファイルに保存するには、関数を変更する必要があります。関数内ではfit
、チューニング パラメーターの値はわかりますが、モデルがどのリサンプルで構築されたかはわかりません。
これは、非常によく似た質問に対する回答から得られた、これを達成する方法の例です。
# Copy all model structure info from existing model type
cust.mdl <- getModelInfo("rf", regex=FALSE)[[1]]
# Override fit function so that we can save the iteration
cust.mdl$fit <- function(x=x, y=y, wts=wts, param=param, lev=lev, last=last, classProbs=classProbs, ...) {
# Dont save the final pass (dont train the final model across the entire training set)
if(last == TRUE) return(NULL)
# Fit the model
fit.obj <- getModelInfo("rf", regex=FALSE)[[1]]$fit(x, y, wts, param, lev, last, classProbs, ...)
# Create an object with data to save and save it
fit.data <- list(resample=rownames(x),
mdl=fit.obj,
#x, y, wts,
param=param, lev=lev, last=last, classProbs=classProbs,
other=list(...))
# Create a string representing the tuning params
param.str <- paste(lapply(1:ncol(param), function(x) {
paste0(names(param)[x], param[1,x])
}), collapse="-")
save(fit.data, file=paste0("rf_modeliter_", sample(1000:9999,1), "_", param.str, ".RData"))
return (fit.obj)
}
于 2015-08-05T18:01:57.380 に答える