当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R parsnip extract-parsnip 提取防风草模型对象的元素


这些函数从防风草对象中提取各种元素。如果它们尚不存在,则会抛出错误。

用法

# S3 method for model_fit
extract_spec_parsnip(x, ...)

# S3 method for model_fit
extract_fit_engine(x, ...)

# S3 method for model_spec
extract_parameter_set_dials(x, ...)

# S3 method for model_spec
extract_parameter_dials(x, parameter, ...)

参数

x

防风草 model_fit 对象或防风草 model_spec 对象。

...

目前未使用。

parameter

参数 ID 的单个字符串。

从防风草对象 x 中提取的值,如说明部分所述。

细节

提取底层引擎拟合有助于说明模型(通过 print()summary()plot() 等)或变量重要性/解释器。

但是,用户不应在提取的模型上调用predict() 方法。 parsnip 在将数据提供给模型之前可能已对数据执行了预处理操作。绕过这些可能会导致错误或默默地生成不正确的预测。

好的

   parsnip_fit %>% predict(new_data)

坏的

   parsnip_fit %>% extract_fit_engine() %>% predict(new_data)

例子

lm_spec <- linear_reg() %>% set_engine("lm")
lm_fit <- fit(lm_spec, mpg ~ ., data = mtcars)

lm_spec
#> Linear Regression Model Specification (regression)
#> 
#> Computational engine: lm 
#> 
extract_spec_parsnip(lm_fit)
#> Linear Regression Model Specification (regression)
#> 
#> Computational engine: lm 
#> 
#> Model fit template:
#> stats::lm(formula = missing_arg(), data = missing_arg(), weights = missing_arg())

extract_fit_engine(lm_fit)
#> 
#> Call:
#> stats::lm(formula = mpg ~ ., data = data)
#> 
#> Coefficients:
#> (Intercept)          cyl         disp           hp         drat  
#>    12.30337     -0.11144      0.01334     -0.02148      0.78711  
#>          wt         qsec           vs           am         gear  
#>    -3.71530      0.82104      0.31776      2.52023      0.65541  
#>        carb  
#>    -0.19942  
#> 
lm(mpg ~ ., data = mtcars)
#> 
#> Call:
#> lm(formula = mpg ~ ., data = mtcars)
#> 
#> Coefficients:
#> (Intercept)          cyl         disp           hp         drat  
#>    12.30337     -0.11144      0.01334     -0.02148      0.78711  
#>          wt         qsec           vs           am         gear  
#>    -3.71530      0.82104      0.31776      2.52023      0.65541  
#>        carb  
#>    -0.19942  
#> 
源代码:R/extract.R

相关用法


注:本文由纯净天空筛选整理自Max Kuhn等大神的英文原创作品 Extract elements of a parsnip model object。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。