Thursday 23 May 2019

DT New

library("partykit")
airq <- subset(airquality, !is.na(Ozone))
ct <- ctree(Ozone ~ ., data = airq)
partykit:::.list.rules.party(ct)
________________________________________

detach("package:partykit", unload=TRUE)
library(party)
airct <- party::ctree(Ozone ~ ., data = airq)

t(sapply(unique(where(airct)), function(x) {
  n <- nodes(airct, x)[[1]]
  Ozone <- airq[as.logical(n$weights), "Ozone"]
  cbind.data.frame("Node" = as.integer(x),
                   "n" = length(Ozone),
                   "Avg."= mean(Ozone),
                   "Variance"= var(Ozone),
                   "SSE" = sum((Ozone - mean(Ozone))^2))
}))
___________________________________________

sum of squared errors of prediction (SSE)
_________________________________________

#print P values

terNodes <- unique(where(airct))
setdiff(1:max(terNodes), terNodes)

sapply(setdiff(1:max(terNodes), terNodes), function(x) {
          n <- nodes(airct, x)[[1]]
          pvalue <- 1 - nodes(airct, x)[[1]]$criterion$maxcriterion
          plab <- ifelse(pvalue < 10^(-3),
                         paste("p <", 10^(-3)),
                         paste("p =", round(pvalue, digits = 3)))
          c("Node" = x, "P-value" = plab)
})
________________________________________________
# print values from the node in ctree

a1=where(output)
table(a1)
print(a1)

input$x1=where(output)
View(input)

N4=subset(input,input$x1==4)
N5=subset(input,input$x1==5)
N6=subset(input,input$x1==6)
N7=subset(input,input$x1==7)

View(N1)


_________________________________________

No comments:

Post a Comment