Overview
APLRRegressor and APLRClassifier are interpretable glassbox model wrappers around the Automatic Piecewise Linear Regression (APLR) algorithm, providing both global and local explanations within the InterpretML framework.
Description
This module wraps the external aplr package to provide APLR models that conform to the InterpretML explainer API. APLR builds piecewise linear models that are inherently interpretable, supporting both main effects and two-way interactions.
- APLRRegressor: Extends
APLRRegressorNative (from the aplr package), RegressorMixin, and ExplainerMixin. Supports regression tasks with global feature importance visualizations (horizontal bar charts and per-term shape plots) and local per-instance contribution explanations.
- APLRClassifier: Extends
APLRClassifierNative (from the aplr package), ClassifierMixin, and ExplainerMixin. Supports multi-class classification by internally using per-class logit APLR models. Provides global explanations broken down by class and local explanations for each instance.
- APLRExplanation: Custom explanation class extending
FeatureValueExplanation that handles visualization for global summaries (bar charts of term importances), per-term shape functions (line plots for univariate, heatmaps for interactions), and local breakdowns.
The module also includes helper functions for density calculation (calculate_densities), feature name management (define_feature_names), unique value counting (calculate_unique_values), and local explanation value creation (create_values).
Usage
Use APLRRegressor for regression tasks where you need an inherently interpretable piecewise linear model with automatic term selection. Use APLRClassifier for classification tasks with the same interpretability properties. Both require the external aplr package to be installed (pip install aplr).
Code Reference
Source Location
Signature
class APLRRegressor(APLRRegressorNative, RegressorMixin, ExplainerMixin):
available_explanations = ["local", "global"]
explainer_type = "model"
def __init__(self, **kwargs):
def fit(self, X, y, **kwargs):
def explain_global(self, name: Optional[str] = None):
def explain_local(self, X: FloatMatrix, y: FloatVector = None, name: Optional[str] = None):
class APLRClassifier(APLRClassifierNative, ClassifierMixin, ExplainerMixin):
available_explanations = ["local", "global"]
explainer_type = "model"
def __init__(self, **kwargs):
def fit(self, X, y, **kwargs):
def explain_global(self, name: Optional[str] = None):
def explain_local(self, X: FloatMatrix, y: FloatVector = None, name: Optional[str] = None):
class APLRExplanation(FeatureValueExplanation):
def __init__(self, explanation_type, internal_obj, feature_names=None,
feature_types=None, name=None, selector=None):
def visualize(self, key=None):
Import
from interpret.glassbox import APLRRegressor, APLRClassifier
I/O Contract
APLRRegressor
Constructor Inputs
| Name |
Type |
Required |
Description
|
| **kwargs |
varies |
No |
Keyword arguments passed to the underlying APLRRegressorNative constructor
|
fit Inputs
| Name |
Type |
Required |
Description
|
| X |
numpy array, pandas DataFrame, or list |
Yes |
Feature matrix (numeric values only)
|
| y |
numpy array |
Yes |
Target vector for regression
|
| **kwargs |
varies |
No |
Additional fit arguments; X_names can specify feature names
|
explain_global Outputs
| Name |
Type |
Description
|
| explanation |
APLRExplanation |
Global explanation with term importances and per-term shape functions
|
explain_local Outputs
| Name |
Type |
Description
|
| explanation |
APLRExplanation |
Local explanation with per-instance feature contribution breakdowns
|
APLRClassifier
Constructor Inputs
| Name |
Type |
Required |
Description
|
| **kwargs |
varies |
No |
Keyword arguments passed to the underlying APLRClassifierNative constructor
|
fit Inputs
| Name |
Type |
Required |
Description
|
| X |
numpy array, pandas DataFrame, or list |
Yes |
Feature matrix (numeric values only)
|
| y |
array-like |
Yes |
Target labels (converted to strings internally)
|
| **kwargs |
varies |
No |
Additional fit arguments; X_names can specify feature names
|
explain_global / explain_local Outputs
| Name |
Type |
Description
|
| explanation |
APLRExplanation |
Explanation object with global term importances per class or local per-instance breakdowns
|
Usage Examples
Regression Example
from interpret.glassbox import APLRRegressor
import numpy as np
X_train = np.random.randn(100, 5)
y_train = X_train[:, 0] * 2 + X_train[:, 1] + np.random.randn(100) * 0.1
model = APLRRegressor()
model.fit(X_train, y_train, X_names=["f0", "f1", "f2", "f3", "f4"])
# Global explanation
global_exp = model.explain_global(name="APLR Global")
global_exp.visualize(key=None) # Overall feature importances
# Local explanation
local_exp = model.explain_local(X_train[:5], y_train[:5], name="APLR Local")
local_exp.visualize(key=0) # First instance explanation
Classification Example
from interpret.glassbox import APLRClassifier
from sklearn.datasets import load_iris
X, y = load_iris(return_X_y=True)
model = APLRClassifier()
model.fit(X, y, X_names=["sepal_l", "sepal_w", "petal_l", "petal_w"])
global_exp = model.explain_global(name="APLR Classifier")
global_exp.visualize(key=None)
Related Pages