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

Tidymodels判别分析报错:prune_method需为单个字符串值

错误原因分析:prune_method参数设置问题

问题代码

flexible_model <- 
  discrim_flexible( mode = "classification",
                    num_terms = tune(),
                    prod_degree = tune(),
                    prune_method = tune,
                    engine = "earth"
  )

set.seed(123)
flexible_wf <-
  workflow() %>%
  add_model(flexible_model) %>% 
  add_recipe(model_recipe)
flexible_wf


flexible_results <-
  flexible_wf %>% 
  tune_grid(resamples = heart_cv,
            metrics = metric_set(accuracy)
  )

报错信息

Fold01: preprocessor 1/1, model 1/10: Error: prune_method should be a single string value

错误原因

  1. 语法错误:prune_method = tune这里漏写了函数括号,正确的调参标记写法是prune_method = tune(),直接写tune会把函数对象本身当作参数值传入,不符合参数要求的字符串类型。
  2. 参数类型要求:prune_method本身需要传入单个字符串(比如"backward"、"none"这类合法取值),即使要对该参数调参,也得先通过tune()正确标记它为待调项,后续再通过调参网格指定该参数的可选字符串范围。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 16:27:23