如何在tidymodels的workflow_set中添加blueprint参数
错误原因
你触发报错的核心原因是option_add()要求所有传入的配置项为命名键值对,你直接传入未命名的update_blueprint(blueprint = sparse_bp)不符合函数参数要求,导致所有工作流未正常运行,后续调用绘图、指标收集函数时就会返回无结果的报错。
正确实现方式
方式1:预先给预处理流程指定blueprint
如果你的model_vars是recipe对象,可以先给预处理流程配置好blueprint再传入workflow_set:
# 构造带稀疏矩阵blueprint的预处理列表 preproc_list <- list( simple = model_vars %>% add_recipe(blueprint = sparse_bp) ) no_pre_proc <- workflow_set( preproc = preproc_list, models = list(MARS = mars_spec, CART = cart_spec, CART_bagged = bag_cart_spec, RF = rf_spec, boosting = xgb_spec, Cubist = cubist_spec) )
方式2:通过option_add正确传入参数
如果要批量给所有工作流的add_recipe步骤传递blueprint参数,按如下格式调用option_add即可:
no_pre_proc <- workflow_set( preproc = list(simple = model_vars), models = list(MARS = mars_spec, CART = cart_spec, CART_bagged = bag_cart_spec, RF = rf_spec, boosting = xgb_spec, Cubist = cubist_spec) ) %>% option_add( # 命名参数add_recipe.args对应add_recipe步骤的额外入参 add_recipe.args = list(blueprint = sparse_bp) )
如果只需要给部分工作流配置blueprint,在option_add中增加id参数指定对应工作流的ID即可。
内容的提问来源于stack exchange,提问作者Choc_waffles
相关产品推荐
相关产品推荐

