Learn R Programming

h2o (version 3.40.0.4)

h2o.explain_row: Generate Model Explanations for a single row

Description

Explain the behavior of a model or group of models with respect to a single row of data. The function returns a list of explanations, which are individual units of explanation such as a partial dependence plot or a variable importance plot. Most of the explanations are visual (ggplot plots). These plots can also be created by individual utility functions as well.

Usage

h2o.explain_row(
  object,
  newdata,
  row_index,
  columns = NULL,
  top_n_features = 5,
  include_explanations = "ALL",
  exclude_explanations = NULL,
  plot_overrides = NULL
)

Value

List of outputs with class "H2OExplanation"

Arguments

object

A list of H2O models, an H2O AutoML instance, or an H2OFrame with a 'model_id' column (e.g. H2OAutoML leaderboard).

newdata

An H2OFrame.

row_index

A row index of the instance to explain.

columns

A vector of column names or column indices to create plots with. If specified parameter top_n_features will be ignored.

top_n_features

An integer specifying the number of columns to use, ranked by variable importance (where applicable).

include_explanations

If specified, return only the specified model explanations. (Mutually exclusive with exclude_explanations)

exclude_explanations

Exclude specified model explanations.

plot_overrides

Overrides for individual model explanations, e.g., list(shap_explain_row = list(columns = 5))

Examples

Run this code
if (FALSE) {
library(h2o)
h2o.init()

# Import the wine dataset into H2O:
f <- "https://h2o-public-test-data.s3.amazonaws.com/smalldata/wine/winequality-redwhite-no-BOM.csv"
df <-  h2o.importFile(f)

# Set the response
response <- "quality"

# Split the dataset into a train and test set:
splits <- h2o.splitFrame(df, ratios = 0.8, seed = 1)
train <- splits[[1]]
test <- splits[[2]]

# Build and train the model:
aml <- h2o.automl(y = response,
                  training_frame = train,
                  max_models = 10,
                  seed = 1)

# Create the explanation for whole H2OAutoML object
exa <- h2o.explain_row(aml, test, row_index = 1)
print(exa)

# Create the explanation for the leader model
exm <- h2o.explain_row(aml@leader, test, row_index = 1)
print(exm)
}

Run the code above in your browser using DataLab