ScoringExplainer Class

Defines a scoring model.

If transformations was passed in on original_explainer, those transformations will be carried through to the scoring explainer, it will expect raw data, and by default importances will be returned for raw features. If feature_maps are passed in here (NOT intended to be used at the same time as transformations), the explainer will expect transformed data, and by default importances will be returned for transformed data. In either case, the output can be specified by setting get_raw explicitly to True or False on the explainer's explain method.

Initialize the ScoringExplainer.

If transformations was passed in on original_explainer, those transformations will be carried through to the scoring explainer, it will expect raw data, and by default importances will be returned for raw features. If feature_maps are passed in here (NOT intended to be used at the same time as transformations), the explainer will expect transformed data, and by default importances will be returned for transformed data. In either case, the output can be specified by setting get_raw explicitly to True or False on the explainer's explain method.

Inheritance
azureml._logging.chained_identity.ChainedIdentity
ScoringExplainer

Constructor

ScoringExplainer(original_explainer, feature_maps=None, raw_features=None, engineered_features=None, **kwargs)

Parameters

Name Description
original_explainer
Required
<xref:interpret_community.common.base_explainer.BaseExplainer>

The training time explainer originally used to explain the model.

feature_maps

A list of feature maps from raw to generated feature. The list can be numpy arrays or sparse matrices where each array entry (raw_index, generated_index) is the weight for each raw, generated feature pair. The other entries are set to zero. For a sequence of transformations [t1, t2, ..., tn] generating generated features from raw features, the list of feature maps correspond to the raw to generated maps in the same order as t1, t2, etc. If the overall raw to generated feature map from t1 to tn is available, then just that feature map in a single element list can be passed.

Default value: None
raw_features

Optional list of feature names for the raw features that can be specified if the original explainer computes the explanation on the engineered features.

Default value: None
engineered_features

Optional list of feature names for the engineered features that can be specified if the original explainer has transformations passed in and only computes the importances on the raw features.

Default value: None
original_explainer
Required
<xref:interpret_community.common.base_explainer.BaseExplainer>

The training time explainer originally used to explain the model.

feature_maps
Required

A list of feature maps from raw to generated feature. The list can be numpy arrays or sparse matrices where each array entry (raw_index, generated_index) is the weight for each raw, generated feature pair. The other entries are set to zero. For a sequence of transformations [t1, t2, ..., tn] generating generated features from raw features, the list of feature maps correspond to the raw to generated maps in the same order as t1, t2, etc. If the overall raw to generated feature map from t1 to tn is available, then just that feature map in a single element list can be passed.

raw_features
Required

Optional list of feature names for the raw features that can be specified if the original explainer computes the explanation on the engineered features.

engineered_features
Required

Optional list of feature names for the engineered features that can be specified if the original explainer has transformations passed in and only computes the importances on the raw features.

Methods

explain

Use the model for scoring to approximate the feature importance values of data.

fit

Implement dummy method required to fit scikit-learn pipeline interface.

predict

Use the TreeExplainer and tree model for scoring to get the feature importance values of data.

Wraps the .explain() function.

explain

Use the model for scoring to approximate the feature importance values of data.

abstract explain(evaluation_examples, get_raw)

Parameters

Name Description
evaluation_examples
Required

A matrix of feature vector examples (# examples x # features) on which to explain the model's output.

get_raw
Required

If True, importance values for raw features will be returned. If False, importance values for engineered features will be returned. If unspecified and transformations was passed into the original explainer, raw importance values will be returned. If unspecified and feature_maps was passed into the scoring explainer, engineered importance values will be returned.

Returns

Type Description

For a model with a single output such as regression, this method returns a matrix of feature importance values. For models with vector outputs this function returns a list of such matrices, one for each output. The dimension of this matrix is (# examples x # features).

fit

Implement dummy method required to fit scikit-learn pipeline interface.

fit(X, y=None)

Parameters

Name Description
X
Required

Training data.

y

Training targets.

Default value: None

predict

Use the TreeExplainer and tree model for scoring to get the feature importance values of data.

Wraps the .explain() function.

predict(evaluation_examples)

Parameters

Name Description
evaluation_examples
Required

A matrix of feature vector examples (# examples x # features) on which to explain the model's output.

Returns

Type Description

For a model with a single output such as regression, this returns a matrix of feature importance values. For models with vector outputs this function returns a list of such matrices, one for each output. The dimension of this matrix is (# examples x # features).

Attributes

engineered_features

Get the engineered feature names corresponding to the get_raw=False parameter on explain call.

If the original explainer had transformations passed to it, the engineered features will need to be passed to the scoring explainer constructor using the engineered_features parameter. Otherwise, if feature maps were passed to the scoring explainer, the engineered features will be the same as the features.

Returns

Type Description
list[str],

The engineered feature names, or None if none were given by the user.

features

Get the feature names.

Returns the default feature names if get_raw is not specified on explain call.

Returns

Type Description
list[str],

The feature names, or None if none were given by the user.

raw_features

Get the raw feature names corresponding to the get_raw=True parameter on explain call.

If the original explainer did not have transformations passed to it, and feature_maps have been passed to the scoring explainer, the raw feature names need to be passed into the scoring explainer constructor using the raw_features parameter. Otherwise the raw features will be the same as the features.

Returns

Type Description
list[str],

The raw feature names, or None if none were given by the user.