prediction_explanations

Prediction explanation tools.

Submodules

Package Contents

Functions

explain_predictions

Creates a report summarizing the top contributing features for each data point in the input features.

explain_predictions_best_worst

Creates a report summarizing the top contributing features for the best and worst points in the dataset as measured by error to true labels.

Contents

evalml.model_understanding.prediction_explanations.explain_predictions(pipeline, input_features, y, indices_to_explain, top_k_features=3, include_explainer_values=False, include_expected_value=False, output_format='text', training_data=None, training_target=None, algorithm='shap')[source]

Creates a report summarizing the top contributing features for each data point in the input features.

XGBoost models and CatBoost multiclass classifiers are not currently supported with the SHAP algorithm. To explain XGBoost model predictions, use the LIME algorithm. The LIME algorithm does not currently support any CatBoost models. For Stacked Ensemble models, the SHAP value for each input pipeline’s predict function into the metalearner is used.

Parameters
  • pipeline (PipelineBase) – Fitted pipeline whose predictions we want to explain with SHAP or LIME.

  • input_features (pd.DataFrame) – Dataframe of input data to evaluate the pipeline on.

  • y (pd.Series) – Labels for the input data.

  • indices_to_explain (list[int]) – List of integer indices to explain.

  • top_k_features (int) – How many of the highest/lowest contributing feature to include in the table for each data point. Default is 3.

  • include_explainer_values (bool) – Whether explainer (SHAP or LIME) values should be included in the table. Default is False.

  • include_expected_value (bool) – Whether the expected value should be included in the table. Default is False.

  • output_format (str) – Either “text”, “dict”, or “dataframe”. Default is “text”.

  • training_data (pd.DataFrame, np.ndarray) – Data the pipeline was trained on. Required and only used for time series pipelines.

  • training_target (pd.Series, np.ndarray) – Targets used to train the pipeline. Required and only used for time series pipelines.

  • algorithm (str) – Algorithm to use while generating top contributing features, one of “shap” or “lime”. Defaults to “shap”.

Returns

A report explaining the top contributing features to each prediction for each row of input_features.

The report will include the feature names, prediction contribution, and explainer value (optional).

Return type

str, dict, or pd.DataFrame

Raises
  • ValueError – if input_features is empty.

  • ValueError – if an output_format outside of “text”, “dict” or “dataframe is provided.

  • ValueError – if the requested index falls outside the input_feature’s boundaries.

evalml.model_understanding.prediction_explanations.explain_predictions_best_worst(pipeline, input_features, y_true, num_to_explain=5, top_k_features=3, include_explainer_values=False, metric=None, output_format='text', callback=None, training_data=None, training_target=None, algorithm='shap')[source]

Creates a report summarizing the top contributing features for the best and worst points in the dataset as measured by error to true labels.

XGBoost models and CatBoost multiclass classifiers are not currently supported with the SHAP algorithm. To explain XGBoost model predictions, use the LIME algorithm. The LIME algorithm does not currently support any CatBoost models. For Stacked Ensemble models, the SHAP value for each input pipeline’s predict function into the metalearner is used.

Parameters
  • pipeline (PipelineBase) – Fitted pipeline whose predictions we want to explain with SHAP or LIME.

  • input_features (pd.DataFrame) – Input data to evaluate the pipeline on.

  • y_true (pd.Series) – True labels for the input data.

  • num_to_explain (int) – How many of the best, worst, random data points to explain.

  • top_k_features (int) – How many of the highest/lowest contributing feature to include in the table for each data point.

  • include_explainer_values (bool) – Whether explainer (SHAP or LIME) values should be included in the table. Default is False.

  • metric (callable) – The metric used to identify the best and worst points in the dataset. Function must accept the true labels and predicted value or probabilities as the only arguments and lower values must be better. By default, this will be the absolute error for regression problems and cross entropy loss for classification problems.

  • output_format (str) – Either “text” or “dict”. Default is “text”.

  • callback (callable) – Function to be called with incremental updates. Has the following parameters: - progress_stage: stage of computation - time_elapsed: total time in seconds that has elapsed since start of call

  • training_data (pd.DataFrame, np.ndarray) – Data the pipeline was trained on. Required and only used for time series pipelines.

  • training_target (pd.Series, np.ndarray) – Targets used to train the pipeline. Required and only used for time series pipelines.

  • algorithm (str) – Algorithm to use while generating top contributing features, one of “shap” or “lime”. Defaults to “shap”.

Returns

A report explaining the top contributing features for the best/worst predictions in the input_features.

For each of the best/worst rows of input_features, the predicted values, true labels, metric value, feature names, prediction contribution, and explainer value (optional) will be listed.

Return type

str, dict, or pd.DataFrame

Raises
  • ValueError – If input_features does not have more than twice the requested features to explain.

  • ValueError – If y_true and input_features have mismatched lengths.

  • ValueError – If an output_format outside of “text”, “dict” or “dataframe is provided.

  • PipelineScoreError – If the pipeline errors out while scoring.