Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(randomForest)
- library(ggplot2)
- library(randomForestExplainer)
- n <- 100
- p <- 4
- # Create data:
- xrandom <- matrix(rnorm(n*p)+5, nrow=n)
- colnames(xrandom)<- paste0("x",2:5)
- d <- data.frame(xrandom)
- d$x1 <- factor(sample(1:2, n, replace=T))
- # Equation:
- y <- d$x2 + rnorm(n)/5
- y[d$x1==1] <- y[d$x1==1]+5
- d$y <- y
- # Random Forest:
- fr <- randomForest(y ~ ., data=d,localImp=T)
- # Random Forest Explainer:
- interactions_frame <- min_depth_interactions(fr, names(d)[-6])
- head(interactions_frame, 2)
- variable root_variable mean_min_depth occurrences interaction
- 1 x1 x1 4.670732 0 x1:x1
- 2 x1 x2 2.606190 221 x2:x1
- uncond_mean_min_depth
- 1 1.703252
- 2 1.703252
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement