當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。