r-从mlr中的重采样函数中检索模型



我想检索MLR中重采样函数生成的二进制分类模型(即选定的特征和系数(。下面,您可以找到我的代码示例。它似乎位于结果对象的属性模型中(这里是r$models(,但我找不到它

# 1. Find a synthetic dataset for supervised learning (two classes)
###################################################################
library(mlbench)
data(BreastCancer)
# generate 1000 rows, 21 quantitative candidate predictors and 1 target variable 
p<-mlbench.waveform(1000) 
# convert list into dataframe
dataset<-as.data.frame(p)
# drop thrid class to get 2 classes
dataset2  = subset(dataset, classes != 3)
dataset2  <- droplevels(dataset2  ) 

# 2. Perform cross validation with embedded feature selection using logistic regression
##########################################################################################
library(BBmisc)
library(mlr)
set.seed(123, "L'Ecuyer")
set.seed(21)
# Choice of data 
mCT <- makeClassifTask(data =dataset2, target = "classes")
# Choice of algorithm 
mL <- makeLearner("classif.logreg", predict.type = "prob")
# Choice of cross-validations for folds 
outer = makeResampleDesc("CV", iters = 10,stratify = TRUE)
# Choice of feature selection method
ctrl = makeFeatSelControlSequential(method = "sbs", maxit = NA,beta = 0.001)
# Choice of sampling between training and test within the fold
inner = makeResampleDesc("Holdout",stratify = TRUE)
lrn = makeFeatSelWrapper(mL, resampling = inner, control = ctrl)
r = resample(lrn, mCT, outer, extract = getFeatSelResult,measures = list(mlr::auc,mlr::acc,mlr::brier),models=TRUE)

您必须在列表中深入挖掘。对于第一个模型,例如:

r$models[[1]]$learner.model$opt.result
r$models[[1]]$learner.model$next.model$learner.model

相关内容

  • 没有找到相关文章

最新更新