pycaret.classification.interpret_model#

pycaret.classification.interpret_model(estimator, plot: str = 'summary', feature: str | None = None, observation: int | None = None, use_train_data: bool = False, X_new_sample: DataFrame | None = None, y_new_sample: DataFrame | None = None, save: str | bool = False, **kwargs)[source]#

This function takes a trained model object and returns an interpretation plot based on the test / hold-out set.

This function is implemented based on the SHAP (SHapley Additive exPlanations), which is a unified approach to explain the output of any machine learning model. SHAP connects game theory with local explanations.

For more information: https://shap.readthedocs.io/en/latest/

For more information on Partial Dependence Plot: SauceCat/PDPbox

Example

>>> from pycaret.datasets import get_data
>>> juice = get_data('juice')
>>> from pycaret.classification import *
>>> exp_name = setup(data = juice,  target = 'Purchase')
>>> xgboost = create_model('xgboost')
>>> interpret_model(xgboost)
estimatorobject, default = none

A trained model object to be passed as an estimator. Only tree-based models are accepted when plot type is ‘summary’, ‘correlation’, or ‘reason’. ‘pdp’ plot is model agnostic.

plotstr, default = ‘summary’

Abbreviation of type of plot. The current list of plots supported are (Plot - Name): * ‘summary’ - Summary Plot using SHAP * ‘correlation’ - Dependence Plot using SHAP * ‘reason’ - Force Plot using SHAP * ‘pdp’ - Partial Dependence Plot * ‘msa’ - Morris Sensitivity Analysis * ‘pfi’ - Permutation Feature Importance

feature: str, default = None

This parameter is only needed when plot = ‘correlation’ or ‘pdp’. By default feature is set to None which means the first column of the dataset will be used as a variable. A feature parameter must be passed to change this.

observation: integer, default = None

This parameter only comes into effect when plot is set to ‘reason’. If no observation number is provided, it will return an analysis of all observations with the option to select the feature on x and y axes through drop down interactivity. For analysis at the sample level, an observation parameter must be passed with the index value of the observation in test / hold-out set.

use_train_data: bool, default = False

When set to true, train data will be used for plots, instead of test data.

X_new_sample: pd.DataFrame, default = None

Row from an out-of-sample dataframe (neither train nor test data) to be plotted. The sample must have the same columns as the raw input train data, and it is transformed by the preprocessing pipeline automatically before plotting.

y_new_sample: pd.DataFrame, default = None

Row from an out-of-sample dataframe (neither train nor test data) to be plotted. The sample must have the same columns as the raw input label data, and it is transformed by the preprocessing pipeline automatically before plotting.

save: string or bool, default = False

When set to True, Plot is saved as a ‘png’ file in current working directory. When a path destination is given, Plot is saved as a ‘png’ file the given path to the directory of choice.

**kwargs:

Additional keyword arguments to pass to the plot.

Returns:

None