Llamar a la parcela en realidad no produce trama
Vea el siguiente bucle: llama a la parcela k (k-1) / 2 veces, pero en realidad nunca se producen gráficas. Sin embargo, si cambio el código para llamar las parcelas manualmente (p. Ej., Plot (my_tree, c (1,2) ), ..), se producen parcelas.)
my_tree es un objeto GBM. Vea el código completo a continuación
#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)
}
}
==== programa completo abajo
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)
}
}