我需要绘制一个条件推理树。我选择了party::ctree() 函数。它适用于 iris 数据集。
library(party)
(irisct_party <- party::ctree(Species ~ .,data = iris))
plot(irisct_party)
但是当我使用随机数据时
library(wakefield)
set.seed(123)
n=200
studs <- data.frame(problem = factor(answer(n, x = c("No", "Yes"))),
age = round(runif(n, 18, 25)),
gender = factor(answer(n, x = c("M", "F" ))),
smoker = factor(answer(n, x = c("No", "Yes" ))),
before = round(runif(n, 60, 80)),
after = before + round(runif(n, 10, 20))
)
(ct <- party::ctree(problem ~ ., data = studs))
plot(ct)
我只看到
Conditional inference tree with 1 terminal nodes
Response: problem
Inputs: age, gender, smoker, before, after
Number of observations: 200
1)* weights = 200
问题。为什么条件推理树在随机数据上有 1 个终端节点?