這些函數從防風草對象中提取各種元素。如果它們尚不存在,則會拋出錯誤。
-
extract_spec_parsnip()
返回防風草模型規範。 -
extract_fit_engine()
返回嵌入防風草模型擬合中的引擎特定擬合。例如,當將linear_reg()
與"lm"
引擎一起使用時,這將返回底層lm
對象。 -
extract_parameter_dials()
返回單個撥號參數對象。 -
extract_parameter_set_dials()
返回一組撥號參數對象。
用法
# 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, ...)
細節
提取底層引擎擬合有助於說明模型(通過 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 parsnip logistic_reg 邏輯回歸
- R parsnip predict.model_fit 模型預測
- R parsnip linear_reg 線性回歸
- R parsnip C5_rules C5.0 基於規則的分類模型
- R parsnip set_engine 聲明計算引擎和特定參數
- R parsnip condense_control 將控製對象壓縮為更小的控製對象
- R parsnip control_parsnip 控製擬合函數
- R parsnip augment 通過預測增強數據
- R parsnip repair_call 修複模型調用對象
- R parsnip dot-model_param_name_key 翻譯模型調整參數的名稱
- R parsnip glm_grouped 將數據集中的分組二項式結果與個案權重擬合
- R parsnip rule_fit 規則擬合模型
- R parsnip svm_rbf 徑向基函數支持向量機
- R parsnip set_args 更改模型規範的元素
- R parsnip translate 解決計算引擎的模型規範
- R parsnip max_mtry_formula 根據公式確定 mtry 的最大值。此函數可能會根據公式和數據集限製 mtry 的值。對於生存和/或多變量模型來說,這是一種安全的方法。
- R parsnip svm_linear 線性支持向量機
- R parsnip set_new_model 注冊模型的工具
- R parsnip rand_forest 隨機森林
- R parsnip mlp 單層神經網絡
- R parsnip nearest_neighbor K-最近鄰
- R parsnip parsnip_update 更新型號規格
- R parsnip fit 將模型規範擬合到數據集
- R parsnip boost_tree 增強樹
- R parsnip bart 貝葉斯加性回歸樹 (BART)
注:本文由純淨天空篩選整理自Max Kuhn等大神的英文原創作品 Extract elements of a parsnip model object。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。