gpt4 book ai didi

machine-learning - 使用 mlr3pipeline 编码和缩放后,无法通过 mlr3proba 训练数据集

转载 作者:行者123 更新时间:2023-12-04 07:43:34 26 4
gpt4 key购买 nike

当我在使用 mlr3pipeline 编码和缩放我的数据集后运行下面的代码以在 mlr3proba 中训练模型时:

task =tsk("sonar")
learner = lrn("classif.rpart")
measure = msr("classif.ce")
inner.rsmp <- rsm("cv", folds = 5)
train_set = sample(task$nrow, 0.8 * task$nrow)
test_set = setdiff(seq_len(task$nrow), train_set)

learner <- po("encode") %>>% po("scale") %>>% po("learner", learner)
learner$train(task, row_ids = train_set)
R 代码显示如下错误:
Error in learner$train(task, row_ids = train_set) : 
unused argument (row_ids = train_set)
我在另一个数据集中尝试过这个,但它显示了同样的问题。
但如果我不编码和缩放我的数据集,一切正常。
另外,对于 resample()功能,没关系(尽管编码和缩放):
rr <- resample(task, learner, inner.rsmp)
rr$aggregate(measure)

#Results:

INFO [08:46:55.411] [mlr3] Applying learner 'encode.scale.classif.rpart' on task 'sonar' (iter 4/5)
INFO [08:46:55.539] [mlr3] Applying learner 'encode.scale.classif.rpart' on task 'sonar' (iter 1/5)
INFO [08:46:55.644] [mlr3] Applying learner 'encode.scale.classif.rpart' on task 'sonar' (iter 2/5)
INFO [08:46:55.773] [mlr3] Applying learner 'encode.scale.classif.rpart' on task 'sonar' (iter 5/5)
INFO [08:46:55.876] [mlr3] Applying learner 'encode.scale.classif.rpart' on task 'sonar' (iter 3/5)

rr$score(measure)

task task_id learner learner_id resampling
1: <TaskClassif[46]> sonar <GraphLearner[33]> encode.scale.classif.rpart <ResamplingCV[19]>
2: <TaskClassif[46]> sonar <GraphLearner[33]> encode.scale.classif.rpart <ResamplingCV[19]>
3: <TaskClassif[46]> sonar <GraphLearner[33]> encode.scale.classif.rpart <ResamplingCV[19]>
4: <TaskClassif[46]> sonar <GraphLearner[33]> encode.scale.classif.rpart <ResamplingCV[19]>
5: <TaskClassif[46]> sonar <GraphLearner[33]> encode.scale.classif.rpart <ResamplingCV[19]>
resampling_id iteration prediction classif.ce
1: cv 1 <PredictionClassif[19]> 0.3333333
2: cv 2 <PredictionClassif[19]> 0.2142857
3: cv 3 <PredictionClassif[19]> 0.2380952
4: cv 4 <PredictionClassif[19]> 0.3658537
5: cv 5 <PredictionClassif[19]> 0.2439024
那么问题出在哪里呢?

最佳答案

您需要将学习器包装在 GraphLearner PipeOp 中:

library(mlr3)
library(mlr3pipelines)

task =tsk("sonar")
learner = lrn("classif.rpart")
measure = msr("classif.ce")
inner.rsmp <- rsmp("cv", folds = 5)
train_set = sample(task$nrow, 0.8 * task$nrow)
test_set = setdiff(seq_len(task$nrow), train_set)

learner <- po("encode") %>>% po("scale") %>>% po("learner", learner)
learner <- GraphLearner$new(learner)
learner$train(task, row_ids = train_set)
learner$predict(task, row_ids = test_set)
#> <PredictionClassif> for 42 observations:
#> row_ids truth response
#> 5 R R
#> 12 R R
#> 13 R R
#> ---
#> 188 M M
#> 191 M M
#> 201 M M
创建于 2021-04-30 由 reprex package (v0.3.0)

关于machine-learning - 使用 mlr3pipeline 编码和缩放后,无法通过 mlr3proba 训练数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67318846/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com