我无法使用 partykit 包的 mob 函数来进行单变量 MLE 拟合。
# Trying to convert vignette example here https://cran.r-project.org/web/packages/partykit/vignettes/mob.pdf on page 7 to do univariate MLE gamma fits.
data("PimaIndiansDiabetes", package = "mlbench")
library("partykit")
library("fitdistrplus")
# Generating some fake data to replace the example data.
op <- options(digits = 3)
set.seed(123)
x <- rgamma(nrow(PimaIndiansDiabetes), shape = 5, rate = 0.1)
PimaIndiansDiabetes$diabetes<-x
PimaIndiansDiabetes$glucose<-x
#Hopefully this change to the formula means fit a gamma to just the diabetes vector of values!
pid_formula <- diabetes ~ 1 | …
Run Code Online (Sandbox Code Playgroud) 我在 R 中创建了一个回归树。这是代码:
tree <- rpart(y~., method="anova", minsplit=20, minbucket=20, maxdepth=3, data=foo)
plot(as.party(tree), terminal_panel = node_boxplot)
Run Code Online (Sandbox Code Playgroud)
我希望我的终端节点包含一个条形图,而不是显示中位数和 IQR 的箱线图,其中一个条形显示平均值和标准偏差误差条。我已经测试了所有 terminal_panel 选项,但没有一个这样做。有什么建议?
我有一个因变量来通过决策树进行分类.它由三类频率组成:738(19%),426(15%)和1800(66%).正如你想象的那样,预测的类别总是第三个,但树的目的是描述性的,所以它实际上并不重要.问题是,当通过ctree()
功能(包partykit
)绘制树时,终端节点显示直方图,其显示三个类的出现概率.我需要修改这个输出:我想获得终端节点中每个类相对于类的绝对频率的出现比例.例如,class1中738个参与者中的哪一个属于某个终端节点?每个终端节点将为组成因变量的所有三个类显示该值.
Bellow一个树的图,默认情况下报告终端节点中每个类的普遍性.
在 IRIS 数据集中。
library("party")
set.seed(1)
x <- ctree(Species ~ ., data=iris)
print(x)
# Conditional inference tree with 4 terminal nodes
#
# Response: Species
# Inputs: Sepal.Length, Sepal.Width, Petal.Length, Petal.Width
# Number of observations: 150
#
# 1) Petal.Length <= 1.9; criterion = 1, statistic = 140.264
# 2)* weights = 50
# 1) Petal.Length > 1.9
# 3) Petal.Width <= 1.7; criterion = 1, statistic = 67.894
# 4) Petal.Length <= 4.8; criterion = 0.999, statistic = 13.865
# …
Run Code Online (Sandbox Code Playgroud)