Description Usage Arguments Value See Also Examples
Plot a 1D or 2D Partial Dependence Plot (PDP)
1 2 3 4 5 6 7 8 |
data |
dataframe - Data to use for the predictions. Should have same columns as training data (can be training data) |
model |
model object - Model to produce PDP from |
explain_col |
string - Vector of length 1 for 1D plot or length 2 for 2D plot. This is the factor(s) to explain in the model. The columns must be in |
weight |
numeric - Vector of length |
n_bins |
numeric - Vector of length 1 for 1D plot and 1 or 2 for 2D plots. This is the number of points to calculate the PDP for |
use_plotly |
Optional: boolean - If TRUE plotly object is returned else ggplot2 object |
plotly/ggplot object of PDP plot
plot_ALE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | data <- data.frame(x1=runif(100, 0, 25), x2=runif(100, 0, 25)) %>%
dplyr::mutate(target=x1^2 * 0.01 + x2 + rnorm(n(),sd=5))
#LM
model_lm <- glm(target ~ poly(x1, 2) + x2, data=data)
plot_PDP(data, model_lm, explain_col="x1", n_bins=5)
plot_PDP(data, model_lm, explain_col="x2", n_bins=5)
plot_PDP(data, model_lm, explain_col=c("x1","x2"), n_bins=5)
#GLM
model_glm <- glm(target ~ poly(x1, 2) + x2, data=data)
plot_PDP(data, model_glm, explain_col="x1", n_bins=5)
plot_PDP(data, model_glm, explain_col="x2", n_bins=5)
plot_PDP(data, model_glm, explain_col=c("x1","x2"), n_bins=5)
#GBM
model_gbm <- xgboost(data = as.matrix(data[,which(!(names(data)=="target"))]), label=data[["target"]], nrounds=20, verbose = 0)
plot_PDP(data[,which(!(names(data)=="target"))], model_gbm, explain_col="x1", n_bins=10)
plot_PDP(data[,which(!(names(data)=="target"))], model_gbm, explain_col="x2", n_bins=10)
plot_PDP(data[,which(!(names(data)=="target"))], model_gbm, explain_col=c("x1","x2"), n_bins=10)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.