Actually, I thought I had understood what one can show a with partial dependence plot, but using a very simple hypothetical example, I got rather puzzled. In the following chunk of code I generate three independent variables (a, b, c) and one dependent variable (y) with c showing a close linear relationship with y, while a and b are uncorrelated with y. I make a regression analysis with a boosted regression tree using the R package gbm
:
a <- runif(100, 1, 100)
b <- runif(100, 1, 100)
c <- 1:100 + rnorm(100, mean = 0, sd = 5)
y <- 1:100 + rnorm(100, mean = 0, sd = 5)
par(mfrow = c(2,2))
plot(y ~ a); plot(y ~ b); plot(y ~ c)
Data <- data.frame(matrix(c(y, a, b, c), ncol = 4))
names(Data) <- c("y", "a", "b", "c")
library(gbm)
gbm.gaus <- gbm(y ~ a + b + c, data = Data, distribution = "gaussian")
par(mfrow = c(2,2))
plot(gbm.gaus, i.var = 1)
plot(gbm.gaus, i.var = 2)
plot(gbm.gaus, i.var = 3)
Not surprisingly, for variables a and b the partial dependence plots yield horizontal lines around the mean of a. What me puzzles is the plot for variable c. I get horizontal lines for the ranges c < 40 and c > 60 and the y-axis is restricted to values close to the mean of y. Since a and b are completely unrelated to y (and thus there variable importance in the model is 0), I expected that c would show partial dependence along its entire range instead of that sigmoid shape for a very restricted range of its values. I tried to find information in Friedman (2001) "Greedy function approximation: a gradient boosting machine" and in Hastie et al. (2011) "Elements of Statistical Learning", but my mathematical skills are too low to understand all the equations and formulae therein. Thus my question: What determines the shape of the partial dependence plot for variable c? (Please explain in words comprehensible to a non-mathematician!)
ADDED on 17th April 2014:
While waiting for a response, I used the same example data for an analysis with R-package randomForest
. The partial dependence plots of randomForest resemble much more to what I expected from the gbm plots: the partial dependence of explanatory variables a and b vary randomly and closely around 50, while explanatory variable c shows partial dependence over its entire range (and over almost the entire range of y). What could be the reasons for these different shapes of the partial dependence plots in gbm
and randomForest
?
Here the modified code that compares the plots:
a <- runif(100, 1, 100)
b <- runif(100, 1, 100)
c <- 1:100 + rnorm(100, mean = 0, sd = 5)
y <- 1:100 + rnorm(100, mean = 0, sd = 5)
par(mfrow = c(2,2))
plot(y ~ a); plot(y ~ b); plot(y ~ c)
Data <- data.frame(matrix(c(y, a, b, c), ncol = 4))
names(Data) <- c("y", "a", "b", "c")
library(gbm)
gbm.gaus <- gbm(y ~ a + b + c, data = Data, distribution = "gaussian")
library(randomForest)
rf.model <- randomForest(y ~ a + b + c, data = Data)
x11(height = 8, width = 5)
par(mfrow = c(3,2))
par(oma = c(1,1,4,1))
plot(gbm.gaus, i.var = 1)
partialPlot(rf.model, Data[,2:4], x.var = "a")
plot(gbm.gaus, i.var = 2)
partialPlot(rf.model, Data[,2:4], x.var = "b")
plot(gbm.gaus, i.var = 3)
partialPlot(rf.model, Data[,2:4], x.var = "c")
title(main = "Boosted regression tree", outer = TRUE, adj = 0.15)
title(main = "Random forest", outer = TRUE, adj = 0.85)