我有一個名爲的包列表。它是從mlr包(僞)代碼的一些迴歸方法的結果如下所示。我想從中提取彙總的性能結果每個任務。例如,如何從$ visc.1 $ regr.rpart和$ visc.2 $ regr.rpart訪問「Aggr。perf」值。我可以單獨訪問它們,但我認爲必須有一個更簡單的方法。從R列表中提取結果
> 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。
請使用'dput'顯示一個SMaL公司重複的例子, – akrun
你的意思,而不是使用打印dput?它產生更多的結果。 – remo
因爲它是一個列表,所以最好只有幾個列表元素,即'dput(bag [1:2])',你想要提取什麼,即你的預期輸出 – akrun