0

parsnip我正在尝试使用and创建节点链接图(决策树)tidymodels。我正在执行的是使用tidymodels包和rpart模型引擎为 StackOverflow 数据集构建决策树模型。该模型应remote根据编程经验年数years_coded_job​​(( )。career_satisfactiondata_scientistcompany_size_number

我的管道

library(tidyverse)
library(tidymodels)
library(rpart.plot)
library(rpart)
library(rattle)

so <- read_rds(here::here("stackoverflow.rds"))

fit <- rpart(remote ~ years_coded_job + career_satisfaction + data_scientist + company_size_number,
             data = so,
             control = rpart.control(minsplit = 20, minbucket = 2))

fancyRpartPlot(fit, sub = "")

我得到的情节

阴谋

我想知道这是否是确定预测变量的正确方法。由于我没有建立模型,这是正确的方法吗?

4

1 回答 1

1

If you are going and parsnip to fit your model, it's better to use that actual fitted model for any visualizations like this. You can get the underlying engine object from a parsnip model using $fit.

library(tidyverse)
library(tidymodels)
library(rattle)
#> Loading required package: bitops
#> Rattle: A free graphical interface for data science with R.
#> Version 5.4.0 Copyright (c) 2006-2020 Togaware Pty Ltd.
#> Type 'rattle()' to shake, rattle, and roll your data.
data(kyphosis, package = "rpart")

tree_fit <- decision_tree(min_n = 20) %>%
  set_engine("rpart") %>%
  set_mode("classification") %>%
  fit(Kyphosis ~ Age + Number + Start,
      data = kyphosis)

fancyRpartPlot(tree_fit$fit, sub = "")

Created on 2021-05-25 by the reprex package (v2.0.0)

For some kinds of visualizations, you will need to use repair_call().

于 2021-05-25T15:17:31.280 回答