![](/img/trans.png)
[英]Permutation based variable importance (violin) plots for random forest in Tidy models
[英]Integration of Variable importance plots within the tidy modelling framework
有人可以告訴我如何在整潔的建模框架中生成基於排列的變量內插嗎? 目前,我有這個:
library(tidymodels)
# variable importance
final_fit_train %>%
pull_workflow_fit() %>%
vip(geom = "point",
aesthetics = list(color = cbPalette[4],
fill = cbPalette[4])) +
THEME +
ggtitle("Elastic Net")
這會產生:
但是,我想要這樣的東西
我不清楚這個相當新的整潔建模框架如何與當前的 VIP package 集成。 任何可以提供幫助的人。 謝謝!
https://koalaverse.github.io/vip/articles/vip.html (VIP包的API)。
要使用置換計算變量重要性,與使用模型相關變量重要性相比,您只需將幾部分放在一起即可。
讓我們看一個 SVM model 的示例,它沒有模型依賴變量重要性得分。
library(tidymodels)
#> ── Attaching packages ──────────────────────── tidymodels 0.1.1 ──
#> ✓ broom 0.7.0 ✓ recipes 0.1.13
#> ✓ dials 0.0.8 ✓ rsample 0.0.7
#> ✓ dplyr 1.0.0 ✓ tibble 3.0.3
#> ✓ ggplot2 3.3.2 ✓ tidyr 1.1.0
#> ✓ infer 0.5.3 ✓ tune 0.1.1
#> ✓ modeldata 0.0.2 ✓ workflows 0.1.2
#> ✓ parsnip 0.1.2 ✓ yardstick 0.0.7
#> ✓ purrr 0.3.4
#> ── Conflicts ─────────────────────────── tidymodels_conflicts() ──
#> x purrr::discard() masks scales::discard()
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag() masks stats::lag()
#> x recipes::step() masks stats::step()
data("hpc_data")
svm_spec <- svm_poly(degree = 1, cost = 1/4) %>%
set_engine("kernlab") %>%
set_mode("regression")
svm_fit <- workflow() %>%
add_model(svm_spec) %>%
add_formula(compounds ~ .) %>%
fit(hpc_data)
svm_fit
#> ══ Workflow [trained] ════════════════════════════════════════════
#> Preprocessor: Formula
#> Model: svm_poly()
#>
#> ── Preprocessor ──────────────────────────────────────────────────
#> compounds ~ .
#>
#> ── Model ─────────────────────────────────────────────────────────
#> Support Vector Machine object of class "ksvm"
#>
#> SV type: eps-svr (regression)
#> parameter : epsilon = 0.1 cost C = 0.25
#>
#> Polynomial kernel function.
#> Hyperparameters : degree = 1 scale = 1 offset = 1
#>
#> Number of Support Vectors : 2827
#>
#> Objective Function Value : -284.7255
#> Training error : 0.835421
我們的 model 現在已經過訓練,因此可以計算變量重要性。 注意幾個步驟:
pull()
。compounds
。predict()
)。library(vip)
#>
#> Attaching package: 'vip'
#> The following object is masked from 'package:utils':
#>
#> vi
svm_fit %>%
pull_workflow_fit() %>%
vip(method = "permute",
target = "compounds", metric = "rsquared",
pred_wrapper = kernlab::predict, train = hpc_data)
由代表 package (v0.3.0) 於 2020 年 7 月 17 日創建
您可以在此處增加nsim
以多次執行此操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.