Call to Plot erzeugt eigentlich kein Plot
Siehe die folgende Schleife - sie ruft den Plot k (k-1) / 2-mal auf, aber es werden nie wirklich Plots erzeugt ), ..), Parzellen werden erstellt.)
my_tree ist ein GBM-Objekt. Den vollständigen Code finden Sie unten
#there is nothing wrong with this code, but yet it does not work
for (i in my_tree$var.names) {
for (j in my_tree$var.names) {
if (i < j) plot(my_tree, c(i, j), n.trees=best.iter)
}
}
==== Vollständiges Programm unten
pdf("demo.pdf")
N <- 100000
alldata <- data.frame();
train <- factor( ifelse(runif(N)<0.5, 'T', 'V'))
X1 <- rnorm(N);
X2 <- rnorm(N);
X3 <- runif(N);
X4 <- rpois(N, lambda=4);
linear.pred <- -3 + 0.25*X1 + 0.125*X2 - X3 + X4**abs(X1)
temp <- binomial()
y <- rbinom(N, 1, p=temp$linkinv(linear.pred))
alldata <- data.frame(train,X1,X2,X3,X4,y)
rm(train,X1,X2,X3,X4,y,linear.pred)
train <- alldata[alldata$train=='T',]
library(gbm)
my_tree<-gbm(y ~ X1 + X2 + X3 + X4,
distribution="bernoulli",
data=train,
train.fraction=0.5,
interaction.depth=8,
n.trees=300,
shrinkage=0.1,
verbose=TRUE)
best.iter <- gbm.perf(my_tree, method="test")
print(best.iter)
summary(my_tree, ntrees=best.iter)
# make one and two ways
for (i in my_tree$var.names) {
plot(my_tree, i, best.iter)
}
#there is nothing wrong with this code, but yet it does not work
for (i in my_tree$var.names) {
for (j in my_tree$var.names) {
if (i < j) plot(my_tree, c(i, j), n.trees=best.iter)
}
}