vivid
Use:
install.packages('vivid')
then
library(vivid)
mlr3
model:For example, using simulated data from the Friedman benchmark problem 1,
we create a mlr3
model and fit a ranger
random forest First we load the required libraries:
library(mlr3) # To create a model library(mlr3learners) library(ranger)
Then load the data:
myData <- genFriedman(noFeatures = 10, noSamples = 250, sigma = 1, bins = NULL, seed = NULL)
Then create the mlr3
model, using y
as the response:
set.seed(1701) fr_task <- TaskRegr$new(id = "Friedman", backend = myData, target = "y") set.seed(1701) fr_lrn <- lrn("regr.ranger", importance = "permutation") set.seed(1701) fr_mod <- fr_lrn$train(fr_task)
Create a matrix of interaction/importance values using the vivid
package:
set.seed(1701) myMatrix <- vividMatrix(task = fr_task, model = fr_mod, gridSize = 30, normalize = FALSE, seed = NULL, sqrt = FALSE, reorder = TRUE)
Create a HeatMap style plot displaying the importance on the diagonal and interactions on the off-diagonal:
plot(myMatrix, type = "heatMap", plotly = F, intLow = "floralwhite", intHigh = "dodgerblue4", impLow = "white", impHigh = "firebrick1", minImp = NULL, maxImp = NULL, minInt = 0, maxInt = NULL)
Create a Network style plot displaying where the importance is displayed by both the size of the node (the bigger the node, the more important the variable) and the colour of the node (low to high values go from white to red)
plot(myMatrix, type = "network", thresholdValue = 0, label = FALSE, minInt = 0, maxInt = NULL, minImp = 0, maxImp=NULL, labelNudge = 0.05, layout = "circle")
Create a partial dependence pair style plot:
set.seed(1701) ggpdpPairs(task = fr_task, model = fr_mod, gridsize = 10, mat = myMatrix)
Create a zenpath and zenplot layout of the partial dependence:
set.seed(1701) zpath <- calcZpath(myMatrix, cutoff = 0.05) pdpZenplot(task = fr_task, model = fr_mod, gridsize = 10)
Create a plot displaying all interactions:
plot(myMatrix, type = "allInteractions", top = 0)
Create a plot displaying the overall interaction strength:
interactionPlot(model = fr_mod, data = myData, type = "barplot")
Create a plot displaying just the variable importance:
plot(myMatrix, type = "importance", plotType = "barplot")
Generate data from the Friedman benchmark problem 1:
myData <- genFriedman(noFeatures = 10, noSamples = 100, sigma = 1, bins = NULL, seed = NULL) head(myData,3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.