我有一个名为 bag 的列表。这是来自mlr包(伪)代码的许多回归方法的结果如下所示。我想从每个任务 中提取汇总的效果结果。例如,我如何访问" Aggr。 PERF"来自$ visc.1 $ regr.rpart和$ visc.2 $ regr.rpart的值。我可以单独访问它们,但我认为必须有一个更简单的方法。
> class(bag)
[1] "list"
代码生成包(不包括数据集):
library('mlr')
dataset = read.csv("dataset.csv")
regr.task = makeRegrTask(id = "dataset", data = dataset, target = "target")
# feature reduction
fv = generateFilterValuesData(regr.task)
# resampling description
rdesc = makeResampleDesc("Holdout")
####################
bag = NULL
####################
for (i in 1:2)
{
cols = c(order(fv$data$randomForestSRC.rfsrc, decreasing = TRUE)[1:i], ncol(dataset))
dataset.ig = dataset[, cols]
iid = paste(c("dataset", i), collapse = ".")
regr.task = makeRegrTask(id = iid,
data = dataset.ig,
target = "dataset")
# learners
lrns = list(
"regr.bcart"
,"regr.fnn"
,"regr.rpart"
)
set.seed(0, "L'Ecuyer")
bmr = benchmark(lrns, regr.task, rdesc, show.info = FALSE)
#########################
bag = c(bag, bmr)
#########################
}
MWC:
for (i in seq(1,42,3))
{
print (bag[i]$results)
}
输出:
$visc.1
$visc.1$regr.bcart
Resample Result
Task: visc.1
Learner: regr.bcart
Aggr perf: mse.test.mean=5.14e+03
Runtime: 0.181672
$visc.1$regr.cforest
Resample Result
Task: visc.1
Learner: regr.cforest
Aggr perf: mse.test.mean=4.92e+03
Runtime: 0.103091
$visc.1$regr.fnn
Resample Result
Task: visc.1
Learner: regr.fnn
Aggr perf: mse.test.mean=2.44e+03
Runtime: 0.0151947
$visc.1$regr.mars
Resample Result
Task: visc.1
Learner: regr.mars
Aggr perf: mse.test.mean=3.77e+03
Runtime: 0.0163326
$visc.1$regr.rpart
Resample Result
Task: visc.1
Learner: regr.rpart
Aggr perf: mse.test.mean=4.77e+03
Runtime: 0.0265007
$visc.2
$visc.2$regr.bcart
Resample Result
Task: visc.2
Learner: regr.bcart
Aggr perf: mse.test.mean=5.14e+03
Runtime: 0.177014
$visc.2$regr.cforest
Resample Result
Task: visc.2
Learner: regr.cforest
Aggr perf: mse.test.mean=4.95e+03
Runtime: 0.115235
$visc.2$regr.fnn
Resample Result
Task: visc.2
Learner: regr.fnn
Aggr perf: mse.test.mean=3.25e+03
Runtime: 0.0116491
$visc.2$regr.mars
Resample Result
Task: visc.2
Learner: regr.mars
Aggr perf: mse.test.mean=2.67e+03
Runtime: 0.0153017
$visc.2$regr.rpart
Resample Result
Task: visc.2
Learner: regr.rpart
Aggr perf: mse.test.mean=4.77e+03
Runtime: 0.0252295
修改 我还保存了dput(bag [1:2])here。
答案 0 :(得分:0)
根据上述mtcars
示例,从bag
列创建列表。
io <-list(mtcars$mpg, mtcars$cyl, mtcars$disp)
names(io) <- c("mpg","cyl","disp")
class(io)
[1] "list"
io
$mpg
[1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4 10.4 14.7 32.4 30.4 33.9 21.5
[22] 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7 15.0 21.4
$cyl
[1] 6 6 4 6 8 6 8 4 4 6 6 8 8 8 8 8 8 4 4 4 4 8 8 8 8 4 4 4 8 6 8 4
$disp
[1] 160.0 160.0 108.0 258.0 360.0 225.0 360.0 146.7 140.8 167.6 167.6 275.8 275.8 275.8 472.0 460.0 440.0
[18] 78.7 75.7 71.1 120.1 318.0 304.0 350.0 400.0 79.0 120.3 95.1 351.0 145.0 301.0 121.0
实施 MWC :
req_rows <- seq(1,length(io$mpg),3)
req_rows
[1] 1 4 7 10 13 16 19 22 25 28 31
# rather than using loop, use this
io$mpg[io_seq]
[1] 21.0 21.4 14.3 19.2 17.3 10.4 30.4 15.5 19.2 30.4 15.0