从mlr中的重采样功能中检索模型

时间:2018-11-15 12:41:18

标签: r cross-validation 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)

1 个答案:

答案 0 :(得分:0)

您必须在列表中进行更深入的研究。对于第一个模型,例如:

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