Automatic Piecewise Linear Regression (APLR)#

Links to API References: APLRRegressor, APLRClassifier

See the backing repository for APLR here.

Summary

APLR produces inherently interpretable models. The relationship between the response and its explanatory variables are modeled with piecewise linear basis functions. The algorithm automatically handles variable selection, non-linear relationships and interactions. Empirical tests show that APLR is often able to compete with tree-based methods on predictiveness. Predictions from APLR models are usually smoother than those from tree-based methods due to the piecewise linear base learners. APLR can be used for regression tasks and classification tasks, including multiclass classification. The implementation is a light wrapper to the aplr package, adding the explain_global and explain_local methods so that APLR models can be interpreted in the same framework as for example EBMs.

How it Works

A brief introduction to APLR and how to tune APLR models can be found here. The article “Automatic piecewise linear regression” [1] describes APLR in detail and can be found here.

Code Example

The following code will train a logistic regression for the breast cancer dataset. The visualizations provided will be for both global and local explanations.

from interpret import set_visualize_provider
from interpret.provider import InlineProvider

set_visualize_provider(InlineProvider())
import numpy as np
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score

from interpret.glassbox import APLRClassifier
from interpret import show

seed = 42
np.random.seed(seed)
X, y = load_breast_cancer(return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.20, random_state=seed
)

aplr = APLRClassifier(random_state=seed)
aplr.fit(X_train, y_train, X_names=X_train.columns)

auc = roc_auc_score(y_test, aplr.predict_class_probabilities(X_test)[:, 1])
print("AUC: {:.3f}".format(auc))
AUC: 0.996
show(aplr.explain_global())
show(aplr.explain_local(X_test.values[:5], y_test.values[:5]))

Further Resources

Below are more detailed code examples from the backing repository for APLR. This will also work when using APLR through InterpretML if you change from aplr import to from interpret.glassbox import.

Bibliography

[1] von Ottenbreit, M., De Bin, R. Automatic piecewise linear regression. Comput Stat 39, 1867–1907 (2024).