Implementation:Interpretml Interpret ClassificationTree And RegressionTree
| Knowledge Sources | |
|---|---|
| Domains | Machine_Learning, Interpretability |
| Last Updated | 2026-02-07 12:00 GMT |
Overview
ClassificationTree and RegressionTree are shallow decision tree models (default max depth of 3) that wrap scikit-learn's DecisionTreeClassifier and DecisionTreeRegressor, providing interactive tree visualizations for both global and local explanations.
Description
This module implements interpretable decision tree models within the InterpretML framework:
- BaseShallowDecisionTree: Abstract base class that provides the shared implementation for fitting, predicting, and generating both global and local explanations. It extracts the tree structure from scikit-learn's internal
_treerepresentation and converts it to a node/edge graph format suitable for interactive visualization.
- RegressionTree: Concrete regression tree class that wraps scikit-learn's
DecisionTreeRegressor. Inherits fromRegressorMixinandBaseShallowDecisionTree.
- ClassificationTree: Concrete classification tree class that wraps scikit-learn's
DecisionTreeClassifier. Inherits fromClassifierMixinandBaseShallowDecisionTree. Also providespredict_probafor probability estimates.
- TreeExplanation: Custom explanation class that renders tree structures as interactive Dash Cytoscape graphs. Global explanations show the full tree with nodes highlighted when a specific feature is selected. Local explanations highlight the decision path taken for a specific instance.
The tree depth is intentionally kept shallow (default max_depth=3) to maintain interpretability while still capturing key decision boundaries in the data.
Usage
Use ClassificationTree for classification tasks and RegressionTree for regression tasks when you need a simple, visually interpretable model. These are especially useful for quick baseline models, explaining data patterns to non-technical stakeholders, or when regulatory requirements mandate fully transparent models.
Code Reference
Source Location
- Repository: Interpretml_Interpret
- File:
python/interpret-core/interpret/glassbox/_decisiontree.py
Signature
class BaseShallowDecisionTree(ExplainerMixin):
available_explanations = ["global", "local"]
explainer_type = "model"
def __init__(self, feature_names=None, feature_types=None, max_depth=3, **kwargs):
def fit(self, X, y, sample_weight=None, check_input=True):
def predict(self, X):
def explain_global(self, name=None):
def explain_local(self, X, y=None, name=None):
class RegressionTree(RegressorMixin, BaseShallowDecisionTree):
def __init__(self, feature_names=None, feature_types=None, max_depth=3, **kwargs):
def fit(self, X, y, sample_weight=None, check_input=True):
class ClassificationTree(ClassifierMixin, BaseShallowDecisionTree):
def __init__(self, feature_names=None, feature_types=None, max_depth=3, **kwargs):
def fit(self, X, y, sample_weight=None, check_input=True):
def predict_proba(self, X):
Import
from interpret.glassbox import ClassificationTree, RegressionTree
I/O Contract
Constructor Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| feature_names | list of str | No | List of feature names |
| feature_types | list of str | No | List of feature types (e.g. "continuous", "nominal", "ordinal") |
| max_depth | int | No | Maximum depth of the decision tree (default 3) |
| **kwargs | varies | No | Additional keyword arguments passed to scikit-learn's decision tree constructor |
fit Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| X | numpy array or compatible | Yes | Training feature matrix |
| y | numpy array | Yes | Training labels (1-dimensional) |
| sample_weight | numpy array | No | Per-sample weights (default None for equal weights) |
| check_input | bool | No | Whether to bypass input checking (default True) |
explain_global Outputs
| Name | Type | Description |
|---|---|---|
| explanation | TreeExplanation | Global explanation with interactive tree visualization (Dash Cytoscape) |
explain_local Outputs
| Name | Type | Description |
|---|---|---|
| explanation | TreeExplanation | Local explanation highlighting the decision path for each instance |
Usage Examples
Classification Example
from interpret.glassbox import ClassificationTree
from sklearn.datasets import load_iris
X, y = load_iris(return_X_y=True)
ct = ClassificationTree(max_depth=3)
ct.fit(X, y)
# Global explanation - full tree visualization
global_exp = ct.explain_global(name="Iris Classification Tree")
global_exp.visualize(key=None)
# Local explanation - decision path for specific instances
local_exp = ct.explain_local(X[:5], y[:5], name="Iris Local")
local_exp.visualize(key=0)
Regression Example
from interpret.glassbox import RegressionTree
import numpy as np
X = np.random.randn(200, 3)
y = X[:, 0] * 2 + X[:, 1] + np.random.randn(200) * 0.1
rt = RegressionTree(feature_names=["f0", "f1", "f2"], max_depth=4)
rt.fit(X, y)
global_exp = rt.explain_global(name="Regression Tree")
global_exp.visualize(key=None)