Le code promis pour avoir l'arbre du TP5:
#En plus : Plot the decision tree
plotDecisTree <- function(decisTree){
GetNodeLabel <- function(node) switch(node$type,
terminal = paste0( '$ ', format(node$payoff, scientific = FALSE, big.mark = ",")),
paste0('ER\n', '$ ', format(node$payoff, scientific = FALSE, big.mark = ",")))
GetEdgeLabel <- function(node) {
if (!node$isRoot && node$parent$type == 'chance') {
label = paste0(node$name, " (", node$p, ")")
} else {
label = node$name
}
return (label)
}
GetNodeShape <- function(node) switch(node$type, decision = "box",
chance = "circle", terminal = "house")
SetEdgeStyle(decisTree, fontname = 'helvetica', label = GetEdgeLabel)
SetNodeStyle(decisTree, fontname = 'helvetica', label = GetNodeLabel, shape = GetNodeShape)
SetGraphStyle(decisTree, rankdir = "LR")
plot(decisTree)
}
plotDecisTree(decisTree)
#sulp ne
#En plus : Plot the decision tree
plotDecisTree <- function(decisTree){
GetNodeLabel <- function(node) switch(node$type,
terminal = paste0( '$ ', format(node$payoff, scientific = FALSE, big.mark = ",")),
paste0('ER\n', '$ ', format(node$payoff, scientific = FALSE, big.mark = ",")))
GetEdgeLabel <- function(node) {
if (!node$isRoot && node$parent$type == 'chance') {
label = paste0(node$name, " (", node$p, ")")
} else {
label = node$name
}
return (label)
}
GetNodeShape <- function(node) switch(node$type, decision = "box",
chance = "circle", terminal = "house")
SetEdgeStyle(decisTree, fontname = 'helvetica', label = GetEdgeLabel)
SetNodeStyle(decisTree, fontname = 'helvetica', label = GetNodeLabel, shape = GetNodeShape)
SetGraphStyle(decisTree, rankdir = "LR")
plot(decisTree)
}
plotDecisTree(decisTree)
#sulp ne
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.