次のコマンドを使用して、R コンソールで rpart ツリーの結果をテキストで簡単に出力できます。
fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis)
print(fit)
そして、次のように出力されます。
n=81
node), split, n, loss, yval, (yprob) * は終端ノードを表す
1)ルート81 17欠勤(0.79012346 0.20987654)2)Start> = 8.5 62 6 Absant(0.90322581 0.0967419)
4)Start> = 14.5 29 0 ABSENT(1.000000000.000000) * 5)
開始)年齢<55 12 0欠席(1.000000000.00000000) * 11)年齢> = 55 21 6存在(0.71428571 0.28571429) 22)
22)年齢> = 111 14 2欠席(0.85714286 0.14285714) * 23)年齢<111 7 ) * 3) 開始 < 8.5 19 8 現在 (0.42105263 0.57894737) *
ただし、これは Rshiny textOutput では機能しません。
次の Rshiny コードを参照してください。
ui.r
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot"),
textOutput("distText")
)
)
)
server.r
library(shiny)
library(rpart)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
output$distText <- renderText({
fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis)
print(fit)
})
})
上記の光沢のあるアプリを実行すると、次のエラーが発生します。
cat(list(...)、file、sep、fill、labels、append) のエラー:
引数 1 (タイプ 'list') は 'cat' で処理できません