R 调用plot&x27;实际上,我并没有画出情节

R 调用plot&x27;实际上,我并没有画出情节,r,R,请参见下面的循环——它调用了绘图k(k-1)/2次,但从未实际生成绘图。。但是,如果我更改代码以手动调用绘图(例如,绘图(我的_树,c(1,2),…),将生成绘图。) 我的_树是GBM对象。请参阅下面的完整代码 #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) {

请参见下面的循环——它调用了绘图k(k-1)/2次,但从未实际生成绘图。。但是,如果我更改代码以手动调用绘图(例如,绘图(我的_树,c(1,2),…),将生成绘图。)

我的_树是GBM对象。请参阅下面的完整代码

#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)
        }
}
#这段代码没有错,但它不起作用
for(我的_树$var.names中的i){
for(我的_树中的j$var.names){
if(i
==下面是完整的程序

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)
        }
}
pdf(“demo.pdf”)

N如果您查看
plot.gbm
的帮助页面,它提到使用了晶格图,因此这很可能是常见问题7.22的一个例子。尝试“打印”情节。

谢谢您,先生。正如我告诉我的同事,“我确实相信我刚刚得到了常见问题解答。”不管怎样,它的工作都很有魅力。