Share @ LinkedIn Facebook  interpret-ml, interpret-predictions
interpret-ml - Explain Machine Learning Models And Their Predictions [Python]

interpret-ml - Explain Machine Learning Models And Their Predictions

The interpretation of machine learning models and their predictions has become quite important lately. The interpretation of models to better understand which features actually contributed to a particular prediction gives confidence to the model creator. It also helps to better explain why the model is behaving in a particular way. The python has many libraries (like lime, shap, eli5, yellowbrick, etc) which provide different ways to explain model predictions. We have already created tutorials on these libraries (See References section). As a part of this tutorial, we'll be explaining the library named interpret-ml which is designed by the Microsoft research team. The interpret-ml is an open-source library and is built on a bunch of other libraries (plotly, dash, shap, lime, treeinterpreter, sklearn, joblib, jupyter, salib, skope-rules, gevent, and pytest). The interpret-ml creates an interactive dashboard of visualizations using plotly and dash which can explain data, model performance, and predictions from different perspectives. It has divided different explainer classes used for different purposes in different modules. Please make a note that interpret-ml is still in alpha release and constantly getting developed as of the date when this tutorial is created.

We'll be explaining the usage of three main modules as a part of this tutorial.

  • data - It has classes that can help us explain our dataset from a different perspective.
  • glassbox - It has classes that can help us explain our model predictions.
  • perf - It has classes that can help us visualize metrics like proc curve, precision-recall curve, etc.

Data Explainers

Below we have given a list of classes available in the data module of interpret-ml which we'll explain.

  • data
    • ClassHistogram - It creates interactive visualization which shows the distribution of classes in classification problems. It also creates a histogram for individual features based on the individual class of data.
    • Marginal - It creates a marginal plot for provided data.

Model Explainers

Below we have listed down classes available in modules glassbox, blackbox and greybox. We'll be primarily explaining only explainers available from glassbox module. We'll be covering blackbox and greybox in a separate tutorial.

  • glassbox
    • LinearRegression - It helps us explain the linear regression model's prediction on our data.
    • LogisticRegression - It helps us explain the logistic regression model's prediction on our data.
    • ClassificationTree - It helps us explain predictions generated by the decision tree-based model on classification dataset.
    • RegressionTree - It helps us explain predictions generated by the decision tree-based model on the regression dataset.
    • ExplainableBoostingClassifier - It helps us explain predictions generated by boosting-based model on classification dataset.
    • ExplainableBoostingRegressor - It helps us explain predictions generated by a boosting-based model on the regression dataset.
  • blackbox

    • LimeTabular
    • ShapKernel
    • PartialDependence
    • MorrisSensitivity
  • greybox

    • TreeInterpreter
    • ShapTree

Performance Explainers

The perf module provides classes that will help us explain metrics like roc curve, precision-recall curve, etc.

  • perf
    • PR - It helps us generate precision recall curve.
    • ROC - - It helps us generate ROC curve.
    • RegressionPerf - It helps us explain regression metrics like RMSE and R2 score.

Steps Commonly Used to Generate Explanation

We'll be commonly following below mentioned steps when generating explanations explaining data, model prediction, and model performance.

  • Create an explainer instance of one of the above classes.
  • Call explain_* methods on explainer instance which will generate explanation instance.
  • Call interpret_ml.show() passing it explanation object to create visualization. The show method accepts a single explanation object or a list of them.

We'll be using one classification dataset and one regression data to explain classes available from data, glassbox, and perf modules.

We'll start by loading useful libraries.

In [1]:
import interpret
from interpret import glassbox, blackbox, greybox

import pandas as pd
import numpy as np

import sklearn

Classification Problem

As a part of this section, we'll explain the usage of explainers available from data, glassbox, and perf to explain the classification dataset. We'll be using the breast cancer dataset available from scikit-learn as a part of this section. The target variable is whether the tumor is malignant or benign based on a list of features.

Below we have loaded the breast cancer dataset as pandas dataframe as well and printed the first few rows of data. We have even printed a description of features that are available in the dataset.

In [2]:
from sklearn.datasets import load_breast_cancer

breast_cancer = load_breast_cancer()

for line in breast_cancer.DESCR.split("\n")[5:32]:
    print(line)

breast_cancer_df = pd.DataFrame(data=breast_cancer.data, columns = breast_cancer.feature_names)

breast_cancer_df["TumorType"] = [breast_cancer.target_names[cat] for cat in breast_cancer.target]

breast_cancer_df.head()
**Data Set Characteristics:**

    :Number of Instances: 569

    :Number of Attributes: 30 numeric, predictive attributes and the class

    :Attribute Information:
        - radius (mean of distances from center to points on the perimeter)
        - texture (standard deviation of gray-scale values)
        - perimeter
        - area
        - smoothness (local variation in radius lengths)
        - compactness (perimeter^2 / area - 1.0)
        - concavity (severity of concave portions of the contour)
        - concave points (number of concave portions of the contour)
        - symmetry
        - fractal dimension ("coastline approximation" - 1)

        The mean, standard error, and "worst" or largest (mean of the three
        largest values) of these features were computed for each image,
        resulting in 30 features.  For instance, field 3 is Mean Radius, field
        13 is Radius SE, field 23 is Worst Radius.

        - class:
                - WDBC-Malignant
                - WDBC-Benign

Out[2]:
mean radius mean texture mean perimeter mean area mean smoothness mean compactness mean concavity mean concave points mean symmetry mean fractal dimension ... worst texture worst perimeter worst area worst smoothness worst compactness worst concavity worst concave points worst symmetry worst fractal dimension TumorType
0 17.99 10.38 122.80 1001.0 0.11840 0.27760 0.3001 0.14710 0.2419 0.07871 ... 17.33 184.60 2019.0 0.1622 0.6656 0.7119 0.2654 0.4601 0.11890 malignant
1 20.57 17.77 132.90 1326.0 0.08474 0.07864 0.0869 0.07017 0.1812 0.05667 ... 23.41 158.80 1956.0 0.1238 0.1866 0.2416 0.1860 0.2750 0.08902 malignant
2 19.69 21.25 130.00 1203.0 0.10960 0.15990 0.1974 0.12790 0.2069 0.05999 ... 25.53 152.50 1709.0 0.1444 0.4245 0.4504 0.2430 0.3613 0.08758 malignant
3 11.42 20.38 77.58 386.1 0.14250 0.28390 0.2414 0.10520 0.2597 0.09744 ... 26.50 98.87 567.7 0.2098 0.8663 0.6869 0.2575 0.6638 0.17300 malignant
4 20.29 14.34 135.10 1297.0 0.10030 0.13280 0.1980 0.10430 0.1809 0.05883 ... 16.67 152.20 1575.0 0.1374 0.2050 0.4000 0.1625 0.2364 0.07678 malignant

5 rows × 31 columns

Explain Data

As a part of explain data section, we'll be explaining the usage of explainers available from the data module to explain the breast cancer dataset.

ClassHistogram

We can create an instance of this class by passing a list of feature names to the feature_names parameter. It'll create an explainer instance.

In [3]:
from interpret import data

class_hist = data.ClassHistogram(feature_names=breast_cancer.feature_names)
class_hist
Out[3]:
<interpret.data.response.ClassHistogram at 0x7f09d94643c8>

Below we have called the explain_data() method on the explainer instance created in the previous step. We have passed actual data and target to the method. It'll create an explanation object.

In [4]:
hist_explanation = class_hist.explain_data(breast_cancer.data, breast_cancer.target)
hist_explanation
Out[4]:
<interpret.data.response.ClassHistogramExplanation at 0x7f0a18d36048>

Below we have called the show() method passing it explanation instance created in the previous step. It'll generate an interactive dashboard with a dropdown which will let us see various features histogram per class of data.

In [ ]:
from interpret import show

show(hist_explanation)

interpret-ml - Explain Machine Learning Models And Their Predictions

Marginal

This class lets us create a marginal chart. We have created an instance of the Marginal class by giving it a list of feature names. It'll create an explainer instance.

In [6]:
marginal = data.Marginal(feature_names=breast_cancer.feature_names)
marginal
Out[6]:
<interpret.data.response.Marginal at 0x7f09cc2ed278>

Below we have called the explain_data() method on the explainer instance from the previous step by giving data and target to the method. It'll generate an explanation instance which we'll display using the show() method.

In [7]:
marginal_explanation = marginal.explain_data(breast_cancer.data, breast_cancer.target)
marginal_explanation
Out[7]:
<interpret.data.response.MarginalExplanation at 0x7f09cc264160>
In [ ]:
show(marginal_explanation)

interpret-ml - Explain Machine Learning Models And Their Predictions

Explain Model Predictions (Global and Local Explanations)

As a part of this section, we'll explain three different explainer classes available from the glassbox module. We'll first divide our dataset into train (80%) and test (20%) sets using train_test_split() method of sklearn.

In [9]:
from sklearn.model_selection import train_test_split

X_breast_cancer, Y_breast_cancer = breast_cancer.data, breast_cancer.target

print("Dataset Size : ", X_breast_cancer.shape, Y_breast_cancer.shape)

X_train_breast_cancer, X_test_breast_cancer, Y_train_breast_cancer, Y_test_breast_cancer = train_test_split(X_breast_cancer, Y_breast_cancer,
                                                                        train_size=0.80,
                                                                        stratify=Y_breast_cancer,
                                                                        random_state=123)

print("Train/Test Sizes : ", X_train_breast_cancer.shape, X_test_breast_cancer.shape, Y_train_breast_cancer.shape, Y_test_breast_cancer.shape)
Dataset Size :  (569, 30) (569,)
Train/Test Sizes :  (455, 30) (114, 30) (455,) (114,)

1. Logistic Regression

The first explainer that we'll explain uses sklearn's logistic regression for classifying samples. We have below created an instance of class glassbox.LogisticRegression by giving it a list of feature names of data. This is our explainer instance.

In [10]:
from interpret import glassbox

glassbox_lr = glassbox.LogisticRegression(feature_names=breast_cancer.feature_names)
glassbox_lr
Out[10]:
<interpret.glassbox.linear.LogisticRegression at 0x7f09cc2ed7f0>

The logistic regression explainer instance has a method named fit() and score() which lets us fit train data to model and calculate model accuracy on the test dataset.

In [11]:
glassbox_lr.fit(X_train_breast_cancer, Y_train_breast_cancer)
/home/sunny/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/logistic.py:432: FutureWarning:

Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.

Out[11]:
<interpret.glassbox.linear.LogisticRegression at 0x7f09cc2ed7f0>
In [12]:
print("Train Accuracy : %.2f"%glassbox_lr.score(X_train_breast_cancer, Y_train_breast_cancer))
print("Test  Accuracy : %.2f"%glassbox_lr.score(X_test_breast_cancer, Y_test_breast_cancer))
Train Accuracy : 0.95
Test  Accuracy : 0.97

The logistic regression explainer instance has two important methods for explaining model predictions.

  • explain_global()
  • explain_local()

explain_global()

The explain global method generates global weights of the model which are generally available as coef_ and intercept_ attribute of the model.

In [13]:
lr_global_explanation = glassbox_lr.explain_global(name="Breast Cancer Dataset Global Explanation")
lr_global_explanation
Out[13]:
<interpret.glassbox.linear.LinearExplanation at 0x7f09cc1ffba8>
In [ ]:
show(lr_global_explanation)

interpret-ml - Explain Machine Learning Models And Their Predictions

explain_local()

The explain_local() method lets us explain model prediction on an individual sample by showing us a bar chart of how much individual features contributed to this prediction. It accepts a list of samples and their predictions as input for generating an explanation object. Below we have generated an explanation instance on the breast cancer test dataset.

In [15]:
lr_local_explanation = glassbox_lr.explain_local(X_test_breast_cancer, Y_test_breast_cancer,
                                                 name="Breast Cancer Local Explainer")
lr_local_explanation
Out[15]:
<interpret.api.templates.FeatureValueExplanation at 0x7f09cc264390>
In [ ]:
show(lr_local_explanation)

interpret-ml - Explain Machine Learning Models And Their Predictions

2. Decision Tree

The second explainer that we'll explain as a part of this section is ClassificationTree which is a decision tree-based explainer. Below we have created an explainer instance, fitted train data, evaluated the accuracy of the model, and then generated explanation instances for global and local explanations.

We have then plotted both explanation instances using the show() method.

In [17]:
from interpret import glassbox

glassbox_classif_tree = glassbox.ClassificationTree(feature_names=breast_cancer.feature_names)
glassbox_classif_tree

glassbox_classif_tree.fit(X_train_breast_cancer, Y_train_breast_cancer)

print("Train Accuracy : %.2f"%glassbox_classif_tree.score(X_train_breast_cancer, Y_train_breast_cancer))
print("Test  Accuracy : %.2f"%glassbox_classif_tree.score(X_test_breast_cancer, Y_test_breast_cancer))

classif_tree_global_explanation = glassbox_classif_tree.explain_global(name="Breast Cancer Dataset Global Explanation")
classif_tree_local_explanation = glassbox_classif_tree.explain_local(X_test_breast_cancer, Y_test_breast_cancer,
                                                 name="Breast Cancer Local Explainer")
Train Accuracy : 0.97
Test  Accuracy : 0.96
In [ ]:
show(classif_tree_global_explanation)
show(classif_tree_local_explanation)

interpret-ml - Explain Machine Learning Models And Their Predictions

3. Boosting Machines

The third explanation instance that we'll explain as a part of this section is ExplainableBoostingClassifier. It’s based on gradient boosting machines. We have first created an explainer instance, fitted train data, calculated test accuracy, and then generated local/global explanations.

In [19]:
from interpret import glassbox

glassbox_boosting = glassbox.ExplainableBoostingClassifier(feature_names=breast_cancer.feature_names)
glassbox_boosting

glassbox_boosting.fit(X_train_breast_cancer, Y_train_breast_cancer)

print("Train Accuracy : %.2f"%glassbox_boosting.score(X_train_breast_cancer, Y_train_breast_cancer))
print("Test  Accuracy : %.2f"%glassbox_boosting.score(X_test_breast_cancer, Y_test_breast_cancer))

boosting_global_explanation = glassbox_boosting.explain_global(name="Breast Cancer Dataset Global Explanation")
boosting_local_explanation = glassbox_boosting.explain_local(X_test_breast_cancer, Y_test_breast_cancer,
                                                 name="Breast Cancer Local Explainer")
Train Accuracy : 1.00
Test  Accuracy : 0.96
In [ ]:
show(boosting_global_explanation)
show(boosting_local_explanation)

interpret-ml - Explain Machine Learning Models And Their Predictions

Explain Model Performance

As a part of this section, we'll be explaining how to generate the ROC curve and precision-recall curve for classification problems using classes available from the perf module of interpret-ml.

In [21]:
from interpret import perf

PR

Below we have created an explainer instance using the PR class of the perf module. It accepts prediction function and feature names. This is our explainer instance.

In [22]:
precicion_recall = perf.PR(glassbox_lr.predict_proba, feature_names=breast_cancer.feature_names)
precicion_recall
Out[22]:
<interpret.perf.curve.PR at 0x7f09cc07bac8>

explain_perf()

The explainer instance created in the previous step has a method named explain_perf() which accepts data and target variables to generate an explanation instance which has precision-recall curve on that data.

In [23]:
pr_explanation = precicion_recall.explain_perf(X_test_breast_cancer, Y_test_breast_cancer)
pr_explanation
Out[23]:
<interpret.perf.curve.PRExplanation at 0x7f09bf63fc18>
In [ ]:
from interpret import show

show(pr_explanation)

interpret-ml - Explain Machine Learning Models And Their Predictions

ROC

The ROC class will be used for creating an ROC AUC curve for our model. It accepts prediction function and feature names for creating explainer instance.

The explainer instance has a method named explain_perf() which accepts data and targets to generate an explanation instance which will have an ROC curve for that data. We'll then call the show() method passing it this explanation instance to generate the ROC curve on given data.

In [25]:
roc = perf.ROC(glassbox_lr.predict_proba, feature_names=breast_cancer.feature_names)
roc
Out[25]:
<interpret.perf.curve.ROC at 0x7f09be79a978>
In [26]:
roc_explanation = roc.explain_perf(X_test_breast_cancer, Y_test_breast_cancer)
roc_explanation
Out[26]:
<interpret.perf.curve.ROCExplanation at 0x7f09be79a940>
In [ ]:
show(roc_explanation)

interpret-ml - Explain Machine Learning Models And Their Predictions

Dashboard With All Visualizations

The show() method which we have used till now can also accept a list of explanations and generate a dashboard of all visualizations.

Please make a note that the dashboard which you see below will be the default dashboard when you pass a list of explanations. If you don't pass explanations for any section like data or local or global then that section will be empty in the dashboard

In [ ]:
show([hist_explanation, marginal_explanation, lr_global_explanation, lr_local_explanation, roc_explanation, pr_explanation])

interpret-ml - Explain Machine Learning Models And Their Predictions

We can even pass explanations generated across different models to compare performance across models as explained below.

In [ ]:
show([lr_global_explanation, classif_tree_global_explanation, boosting_global_explanation])

interpret-ml - Explain Machine Learning Models And Their Predictions

Regression Problem

As a part of this section, we'll be explaining modules data, glassbox, and perf for a regression problem. We'll be using the Boston housing dataset available from sklearn for this purpose. Below we have loaded the Boston housing dataset and printed feature descriptions. We have also loaded the dataset as a pandas dataframe to show the first few samples.

In [30]:
from sklearn.datasets import load_boston

boston = load_boston()

for line in boston.DESCR.split("\n")[5:30]:
    print(line)

boston_df = pd.DataFrame(data=boston.data, columns = boston.feature_names)

boston_df["Price($)"] = boston.target

boston_df.head()
**Data Set Characteristics:**

    :Number of Instances: 506

    :Number of Attributes: 13 numeric/categorical predictive. Median Value (attribute 14) is usually the target.

    :Attribute Information (in order):
        - CRIM     per capita crime rate by town
        - ZN       proportion of residential land zoned for lots over 25,000 sq.ft.
        - INDUS    proportion of non-retail business acres per town
        - CHAS     Charles River dummy variable (= 1 if tract bounds river; 0 otherwise)
        - NOX      nitric oxides concentration (parts per 10 million)
        - RM       average number of rooms per dwelling
        - AGE      proportion of owner-occupied units built prior to 1940
        - DIS      weighted distances to five Boston employment centres
        - RAD      index of accessibility to radial highways
        - TAX      full-value property-tax rate per $10,000
        - PTRATIO  pupil-teacher ratio by town
        - B        1000(Bk - 0.63)^2 where Bk is the proportion of blacks by town
        - LSTAT    % lower status of the population
        - MEDV     Median value of owner-occupied homes in $1000's

    :Missing Attribute Values: None

    :Creator: Harrison, D. and Rubinfeld, D.L.
Out[30]:
CRIM ZN INDUS CHAS NOX RM AGE DIS RAD TAX PTRATIO B LSTAT Price($)
0 0.00632 18.0 2.31 0.0 0.538 6.575 65.2 4.0900 1.0 296.0 15.3 396.90 4.98 24.0
1 0.02731 0.0 7.07 0.0 0.469 6.421 78.9 4.9671 2.0 242.0 17.8 396.90 9.14 21.6
2 0.02729 0.0 7.07 0.0 0.469 7.185 61.1 4.9671 2.0 242.0 17.8 392.83 4.03 34.7
3 0.03237 0.0 2.18 0.0 0.458 6.998 45.8 6.0622 3.0 222.0 18.7 394.63 2.94 33.4
4 0.06905 0.0 2.18 0.0 0.458 7.147 54.2 6.0622 3.0 222.0 18.7 396.90 5.33 36.2

Explain Data

Below we have generated a marginal plot for the Boston dataset using the Marginal class by giving it feature names as a list.

In [ ]:
from interpret import data


marginal = data.Marginal(feature_names=boston.feature_names)
marginal_explanation = marginal.explain_data(boston.data, boston.target)


show(marginal_explanation)

interpret-ml - Explain Machine Learning Models And Their Predictions

Explain Model Predictions (Global and Local Explanations)

As a part of this section, we'll explain local and global explanations using three different models available with the glassbox module of interpret-ml.

  • LinearRegression
  • RegressionTree
  • ExplainableBoostingRegressor

We have first divided the dataset into the train (80%) and test (20%) sets.

In [32]:
from sklearn.model_selection import train_test_split
from interpret import glassbox

X_boston, Y_boston = boston.data, boston.target

print("Dataset Size : ", X_boston.shape, Y_boston.shape)

X_train_boston, X_test_boston, Y_train_boston, Y_test_boston = train_test_split(X_boston, Y_boston,
                                                                        train_size=0.80,
                                                                        random_state=123)

print("Train/Test Sizes : ", X_train_boston.shape, X_test_boston.shape, Y_train_boston.shape, Y_test_boston.shape)
Dataset Size :  (506, 13) (506,)
Train/Test Sizes :  (404, 13) (102, 13) (404,) (102,)

1. Linear Regression

The first model that we'll use for explaining global and local explanations is Linear Regression. The Linear class of glassbox uses the LinearRegression model available from scikit-learn.

We have first created an instance of LinearRegression which is our explainer object. We have then fitted train data to it and printed the R2 score on test data. We have then created explanation objects for local and global explanations.

We have then created visualizations using the show() method.

In [33]:
glassbox_lr = glassbox.LinearRegression(feature_names=boston.feature_names)

print(type(glassbox_lr))

glassbox_lr.fit(X_train_boston, Y_train_boston)

print("\nTrain R2 Score : %.2f"%glassbox_lr.score(X_train_boston, Y_train_boston))
print("Test  R2 Score : %.2f"%glassbox_lr.score(X_test_boston, Y_test_boston))

lr_global_explanation = glassbox_lr.explain_global(name="Boston Housing Dataset Global Explanation")
lr_local_explanation = glassbox_lr.explain_local(X_test_boston, Y_test_boston,
                                                  name="Boston Housing Dataset Global Explanation")
<class 'interpret.glassbox.linear.LinearRegression'>

Train R2 Score : 0.71
Test  R2 Score : 0.63
In [ ]:
show(lr_global_explanation)
show(lr_local_explanation)

interpret-ml - Explain Machine Learning Models And Their Predictions

2. Decision Tree

The second estimator that we'll explain is RegressionTree. It’s a decision tree-based model. We have created an instance of RegressionTree, fitted train data to it, and evaluated the R2 score on test data. We have then created local and global explanations using explainer object. At last, we are displaying both explanations using the show() method.

In [35]:
glassbox_reg_tree = glassbox.RegressionTree(feature_names=boston.feature_names)

print(type(glassbox_reg_tree))

glassbox_reg_tree.fit(X_train_boston, Y_train_boston)

print("\nTrain R2 Score : %.2f"%glassbox_reg_tree.score(X_train_boston, Y_train_boston))
print("Test  R2 Score : %.2f"%glassbox_reg_tree.score(X_test_boston, Y_test_boston))

reg_tree_global_explanation = glassbox_reg_tree.explain_global(name="Boston Housing Dataset Global Explanation")
reg_tree_local_explanation = glassbox_reg_tree.explain_local(X_test_boston, Y_test_boston,
                                                  name="Boston Housing Dataset Global Explanation")
<class 'interpret.glassbox.decisiontree.RegressionTree'>

Train R2 Score : 0.82
Test  R2 Score : 0.42
In [ ]:
show(reg_tree_global_explanation)
show(reg_tree_local_explanation)

interpret-ml - Explain Machine Learning Models And Their Predictions

3. Boosting Machines

The third instance that we'll explain is ExplainableBoostingRegressor which is based on gradient boosting machines. We'll follow the same process as previous examples to create local and global explanations for the Boston dataset.

In [37]:
glassbox_boosting = glassbox.ExplainableBoostingRegressor(feature_names=boston.feature_names)

print(type(glassbox_boosting))

glassbox_boosting.fit(X_train_boston, Y_train_boston)

print("\nTrain R2 Score : %.2f"%glassbox_boosting.score(X_train_boston, Y_train_boston))
print("Test  R2 Score : %.2f"%glassbox_boosting.score(X_test_boston, Y_test_boston))

boosting_global_explanation = glassbox_boosting.explain_global(name="Boston Housing Dataset Global Explanation")
boosting_local_explanation = glassbox_boosting.explain_local(X_test_boston, Y_test_boston,
                                                  name="Boston Housing Dataset Global Explanation")
<class 'interpret.glassbox.ebm.ebm.ExplainableBoostingRegressor'>

Train R2 Score : 0.96
Test  R2 Score : 0.77
In [ ]:
show(boosting_global_explanation)
show(boosting_local_explanation)

interpret-ml - Explain Machine Learning Models And Their Predictions

Explain Model Performance

As a part of this section, we'll explain performance metrics like RMSE and R2 Score calculations for samples of test data.

RegressionPerf

The RegressionPerf class is responsible for generating visualizations related to regression problems. Below we have generated an instance of RegressionPerf by giving it prediction function and features names as input. This is our explainer instance. We have then called the explain_perf() method on it to generate regression performance metrics explanation. At last, we have displayed an explanation using the show() method.

In [ ]:
from interpret import perf

regression_perf = perf.RegressionPerf(glassbox_lr.predict, feature_names=boston.feature_names)
regression_explanation = regression_perf.explain_perf(X_test_boston, Y_test_boston)

show(regression_explanation)

interpret-ml - Explain Machine Learning Models And Their Predictions



Sunny Solanki  Sunny Solanki