You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在mlr3管道中为过滤器结果添加精选特征列表

在mlr3管道中合并过滤特征与预选特征的实现方法

你不需要自定义过滤器,直接用mlr3中内置的po("select")算子就能实现需求——它可以精准选择你指定的预选特征,再和过滤器输出的特征集合合并。

以下是可直接运行的完整代码:

library(mlr3filters)
library(mlr3fselect)
library(mlr3pipelines) # 需加载该包以使用gunion和featureunion

task_pen = tsk("penguins")

# 信息增益过滤器,筛选Top3特征
po_flt = po("filter", filter = flt("information_gain"), filter.nfeat = 3)

# 手动选择预选特征:island和sex
po_custom = po("select", id = "curated list", selector = c("island", "sex"))

# 构建管道:并行执行过滤器与特征选择,再合并特征集合
graph = gunion(list(po_flt, po_custom)) %>>% po("featureunion")

# 运行管道并查看结果
result = graph$train(task_pen)
result$featureunion.output$feature_names

运行后输出的特征列表会包含过滤器选出的3个特征,加上你指定的island和sex,完全符合预期:

[1] "bill_depth"     "bill_length"    "flipper_length" "island"         "sex"

补充说明

po("select")是mlr3pipelines中专门用于手动特征选择的算子,支持通过列名、索引等方式指定要保留的特征,完全适配你这种需要固定加入预选特征的场景,比自定义过滤器更简洁高效。

内容的提问来源于stack exchange,提问作者Huazhong

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 18:52:52