4
fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis)
8
all(predict(pfit, newdata = kyphosis, type = "node") == fit$where)
13
itree <- J48(Species ~ ., data = iris)
14
pitree <- as.party(itree)
15
all(predict(pitree) == predict(pitree, newdata = iris[, 3:4]))
17
all.equal(predict(itree, type = "prob", newdata = iris), predict(pitree, type = "prob", newdata = iris))
18
all.equal(predict(itree, newdata = iris), predict(pitree, newdata = iris))
20
data("GlaucomaM", package = "ipred")
22
w <- runif(nrow(GlaucomaM))
23
fit <- rpart(Class ~ ., data = GlaucomaM, weights = w)
25
all(predict(pfit, type = "node") == fit$where)
26
tmp <- GlaucomaM[sample(1:nrow(GlaucomaM), 100),]
27
all.equal(predict(fit, type = "prob", newdata = tmp), predict(pfit, type = "prob", newdata = tmp))
28
all.equal(predict(fit, type = "class", newdata = tmp), predict(pfit, newdata = tmp))
30
itree <- J48(Class ~ ., data = GlaucomaM)
31
pitree <- as.party(itree)
32
all.equal(predict(itree, newdata = tmp, type = "prob"), predict(pitree, newdata = tmp, type = "prob"))
36
aq <- subset(airquality, !is.na(Ozone))
38
w <- runif(nrow(aq), max = 3)
39
aqr <- rpart(Ozone ~ ., data = aq, weights = w)
42
tmp <- subset(airquality, is.na(Ozone))
43
all.equal(predict(aqr, newdata = tmp), predict(aqp, newdata = tmp))
45
data("GBSG2", package = "ipred")
47
fit <- rpart(Surv(time, cens) ~ ., data = GBSG2)
50
predict(pfit, newdata = GBSG2[1:100,], type = "prob")
51
predict(pfit, newdata = GBSG2[1:100,], type = "response")
54
data.frame(y = gl(4, n), x1 = rnorm(4 * n), x2 = rnorm(4 * n))
57
fit <- as.party(rpart(y ~ ., data = learn))
59
system.time(id <- fitted_node(node_party(fit), test))
60
system.time(yhat <- predict_party(fit, id = id, newdata = test))
62
### multiple responses
64
f[["(response)"]] <- data.frame(srv = f[["(response)"]], hansi = runif(nrow(f)))
65
mp <- party(node_party(pfit), fitted = f, data = pfit$data)
66
class(mp) <- c("constparty", "party")
68
predict(mp, newdata = GBSG2[1:10,])
70
### predictions in info slots
71
tmp <- data.frame(x = rnorm(100))
72
pfit <- party(node = partynode(1L, split = partysplit(1L, breaks = 0),
73
kids = list(partynode(2L, info = -0.5), partynode(3L, info = 0.5))), data = tmp)
75
p <- predict(pfit, newdata = tmp)