2016-12-01 79 views
0

我構建了一個glmtree,並且我想要在我的樹摘要和繪圖中顯示err。Partykit glmtree:在樹摘要中顯示err

我設法通過plot(output_tree, type="simple")

但如何在情節顯示的ERR已經犯錯顯示在我的樹摘要: 我的樹只有攔截,但沒有犯錯

output

回答

0

如果glmtree只有一個截距,那麼它可以被強制爲一個常量擬合樹(constparty)。默認情況下,係數顯示爲強調每個葉子中都建有一個模型。但是如果只有一個截距,那麼用適當比例的響應總結樹也是有意義的。

準備Titanic數據:

data("Titanic", package = "datasets") 
ttnc <- as.data.frame(Titanic) 
ttnc <- ttnc[rep(1:nrow(ttnc), ttnc$Freq), 1:4] 

擬合二項式GLM樹只是截距:

library("partykit") 
tr <- glmtree(Survived ~ ., data = ttnc, family = binomial, alpha = 0.01) 

強制到constparty

tr <- as.constparty(tr) 
tr 
## Model formula: 
## Survived ~ 1 + (Class + Sex + Age) 
## 
## Fitted party: 
## [1] root 
## | [2] Sex in Male 
## | | [3] Class in 1st: No (n = 180, err = 34.4%) 
## | | [4] Class in 2nd, 3rd, Crew 
## | | | [5] Age in Child 
## | | | | [6] Class in 2nd: Yes (n = 11, err = 0.0%) 
## | | | | [7] Class in 3rd: No (n = 48, err = 27.1%) 
## | | | [8] Age in Adult 
## | | | | [9] Class in 2nd, 3rd: No (n = 630, err = 14.1%) 
## | | | | [10] Class in Crew: No (n = 862, err = 22.3%) 
## | [11] Sex in Female 
## | | [12] Class in 3rd: No (n = 196, err = 45.9%) 
## | | [13] Class in 1st, 2nd, Crew: Yes (n = 274, err = 7.3%) 
## 
## Number of inner nodes: 6 
## Number of terminal nodes: 7 
相關問題