Dataset and Model Insights Explainer Demo

This example demonstrates how to use the Dataset and Model Insights Explainer and how to retrieve problems from the interpretation.

[15]:
import logging
import os

import daimojo
import webbrowser

from h2o_sonar import interpret
from h2o_sonar.explainers.dataset_and_model_insights_explainer import DatasetAndModelInsightsExplainer
from h2o_sonar.lib.api.models import ModelApi
[16]:
# dataset
dataset_path = "../../data/predictive/creditcard100_pred_missing_values.csv"
target_col = "predictions"

# model
mojo_path = "../../data/predictive/models/creditcard-binomial.mojo"
mojo_model = daimojo.model(mojo_path)
model = ModelApi().create_model(
    model_src=mojo_model,
    target_col=target_col,
    used_features=list(mojo_model.feature_names),
)

# results
results_location = "./results"
os.makedirs(results_location, exist_ok=True)
[17]:
# parameters
interpret.describe_explainer(DatasetAndModelInsightsExplainer)
[17]:
{'id': 'h2o_sonar.explainers.dataset_and_model_insights_explainer.DatasetAndModelInsightsExplainer',
 'name': 'DatasetAndModelInsightsExplainer',
 'display_name': 'Dataset and model insights explainer',
 'tagline': 'DatasetAndModelInsightsExplainer.',
 'description': 'The explainer checks the dataset and model for various issues. For example, it provides problems and actions for missing values in the target column and a low number of unique values across columns of a dataset.',
 'brief_description': 'DatasetAndModelInsightsExplainer.',
 'model_types': ['iid'],
 'can_explain': ['regression', 'binomial', 'multinomial'],
 'explanation_scopes': ['global_scope'],
 'explanations': [{'explanation_type': 'global-text-explanation',
   'name': 'TextExplanation',
   'category': '',
   'scope': 'global',
   'has_local': '',
   'formats': []}],
 'keywords': [],
 'parameters': [],
 'metrics_meta': []}

Interpret

[18]:
%%capture
interpretation = interpret.run_interpretation(
    dataset=dataset_path,
    model=model,
    target_col=target_col,
    results_location=results_location,
    explainers=[DatasetAndModelInsightsExplainer.explainer_id()],
    log_level=logging.INFO,
)

Interact with the Explainer Result

[19]:
# retrieve the result
result = interpretation.get_explainer_result(DatasetAndModelInsightsExplainer.explainer_id())
[20]:
# open interpretation HTML report in web browser
webbrowser.open(interpretation.result.get_html_report_location())
[20]:
True
[21]:
# summary
result.summary()
[21]:
{'id': 'h2o_sonar.explainers.dataset_and_model_insights_explainer.DatasetAndModelInsightsExplainer',
 'name': 'DatasetAndModelInsightsExplainer',
 'display_name': 'Dataset and model insights explainer',
 'tagline': 'DatasetAndModelInsightsExplainer.',
 'description': 'The explainer checks the dataset and model for various issues. For example, it provides problems and actions for missing values in the target column and a low number of unique values across columns of a dataset.',
 'brief_description': 'DatasetAndModelInsightsExplainer.',
 'model_types': ['iid'],
 'can_explain': ['regression', 'binomial', 'multinomial'],
 'explanation_scopes': ['global_scope'],
 'explanations': [{'explanation_type': 'global-text-explanation',
   'name': 'Dataset and model insights explainer',
   'category': 'CUSTOM',
   'scope': 'global',
   'has_local': None,
   'formats': ['text/plain']}],
 'keywords': [],
 'parameters': [],
 'metrics_meta': []}
[22]:
# parameters
result.params()
[22]:
{}
[23]:
print(
    f"Found {len(interpretation.result.problems)} problems with the dataset. "
    f"Please check the interpretation for further details."
)
Found 2 problems with the dataset. Please check the interpretation for further details.

Save the explainer log and data

[24]:
# save the explainer log
result.log(path="./d_and_m_insights-demo.log")
[25]:
!head d_and_m_insights-demo.log
[ ]: