HessDotPlot: Second derivatives 3D scatter or surface plot against input...

View source: R/HessDotPlot.R

HessDotPlotR Documentation

Second derivatives 3D scatter or surface plot against input values

Description

3D Plot of second derivatives of the neural network output respect to the inputs. This function use plotly instead of ggplot2 to achieve better visualization

Usage

HessDotPlot(
  object,
  fdata = NULL,
  input_vars = "all",
  input_vars2 = "all",
  output_vars = "all",
  surface = FALSE,
  grid = FALSE,
  color = NULL,
  ...
)

Arguments

object

fitted neural network model or array containing the raw second derivatives from the function HessianMLP

fdata

data.frame containing the data to evaluate the second derivatives of the model.

input_vars

character vector with the variables to create the scatter plot in x-axis. If "all", then scatter plots are created for all the input variables in fdata.

input_vars2

character vector with the variables to create the scatter plot in y-axis. If "all", then scatter plots are created for all the input variables in fdata.

output_vars

character vector with the variables to create the scatter plot. If "all", then scatter plots are created for all the output variables in fdata.

surface

logical if TRUE, a 3D surface is created instead of 3D scatter plot (only for combinations of different inputs)

grid

logical. If TRUE, plots created are show together using arrangeGrob. It does not work on Windows platforms due to bugs in plotly library.

color

character specifying the name of a numeric variable of fdata to color the 3D scatter plot.

...

further arguments that should be passed to HessianMLP function

Value

list of 3D geom_point plots for the inputs variables representing the sensitivity of each output respect to the inputs

Examples

## Load data -------------------------------------------------------------------
data("DAILY_DEMAND_TR")
fdata <- DAILY_DEMAND_TR
## Parameters of the NNET ------------------------------------------------------
hidden_neurons <- 5
iters <- 250
decay <- 0.1

################################################################################
#########################  REGRESSION NNET #####################################
################################################################################
## Regression dataframe --------------------------------------------------------
# Scale the data
fdata.Reg.tr <- fdata[,2:ncol(fdata)]
fdata.Reg.tr[,3] <- fdata.Reg.tr[,3]/10
fdata.Reg.tr[,1] <- fdata.Reg.tr[,1]/1000

# Normalize the data for some models
preProc <- caret::preProcess(fdata.Reg.tr, method = c("center","scale"))
nntrData <- predict(preProc, fdata.Reg.tr)

#' ## TRAIN nnet NNET --------------------------------------------------------
# Create a formula to train NNET
form <- paste(names(fdata.Reg.tr)[2:ncol(fdata.Reg.tr)], collapse = " + ")
form <- formula(paste(names(fdata.Reg.tr)[1], form, sep = " ~ "))

set.seed(150)
nnetmod <- nnet::nnet(form,
                      data = nntrData,
                      linear.output = TRUE,
                      size = hidden_neurons,
                      decay = decay,
                      maxit = iters)
# Try HessDotPlot
NeuralSens::HessDotPlot(nnetmod, fdata = nntrData, surface = TRUE, color = "WD")

NeuralSens documentation built on June 22, 2024, 12:06 p.m.