Implementation:Interpretml Interpret RegressionPerf
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Machine_Learning, Interpretability |
| Last Updated | 2026-02-07 12:00 GMT |
Overview
RegressionPerf is a performance evaluation explainer that computes and visualizes regression metrics including RMSE, MSE, MAE, and R-squared for a regression model.
Description
This module provides regression performance evaluation within the InterpretML framework:
- RegressionPerf: Extends
ExplainerMixinwith explainer type "perf". It accepts a regression model (or prediction function), computes predictions on provided data, and calculates standard regression metrics:- MSE (Mean Squared Error) via
sklearn.metrics.mean_squared_error - RMSE (Root Mean Squared Error) as
sqrt(MSE) - MAE (Mean Absolute Error) via
sklearn.metrics.mean_absolute_error - R-squared via
sklearn.metrics.r2_score - Residuals (
y - predictions) with a histogram distribution
- MSE (Mean Squared Error) via
The class explicitly rejects classification models and only supports regression.
- RegressionExplanation: Custom explanation class that visualizes the residual distribution as a density histogram with the RMSE and R-squared values displayed in the plot title.
Usage
Use RegressionPerf when you need to evaluate a regression model's performance and visualize the residual distribution. This is typically used after model training to assess fit quality.
Code Reference
Source Location
- Repository: Interpretml_Interpret
- File:
python/interpret-core/interpret/perf/_regression.py
Signature
class RegressionPerf(ExplainerMixin):
available_explanations = ["perf"]
explainer_type = "perf"
def __init__(self, model, feature_names=None, feature_types=None):
def explain_perf(self, X, y, name=None):
class RegressionExplanation(ExplanationMixin):
def __init__(self, explanation_type, internal_obj, feature_names=None,
feature_types=None, name=None, selector=None):
def data(self, key=None):
def visualize(self, key=None):
Import
from interpret.perf import RegressionPerf
I/O Contract
Constructor Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model | model or callable | Yes | A trained regression model or prediction function |
| feature_names | list of str | No | List of feature names |
| feature_types | list of str | No | List of feature types |
explain_perf Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| X | numpy array or compatible | Yes | Feature matrix to evaluate against |
| y | numpy array | Yes | True continuous response values (1-dimensional) |
| name | str | No | User-defined explanation name |
explain_perf Outputs
| Name | Type | Description |
|---|---|---|
| explanation | RegressionExplanation | Contains MSE, RMSE, MAE, R-squared, residuals, and residual density histogram |
RegressionExplanation Data Dictionary
| Key | Type | Description |
|---|---|---|
| type | str | Always "perf_curve" |
| density | dict | Histogram of residuals with "names" (bin edges) and "scores" (counts) |
| scores | numpy array | Model predictions |
| mse | float | Mean Squared Error |
| rmse | float | Root Mean Squared Error |
| mae | float | Mean Absolute Error |
| r2 | float | R-squared score |
| residuals | numpy array | Residuals (y - predictions) |
Usage Examples
Basic Example
from interpret.perf import RegressionPerf
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
import numpy as np
X = np.random.randn(500, 5)
y = 2 * X[:, 0] + X[:, 1] + np.random.randn(500) * 0.3
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
model = RandomForestRegressor(n_estimators=100).fit(X_train, y_train)
reg_perf = RegressionPerf(model)
perf_exp = reg_perf.explain_perf(X_test, y_test, name="RF Regression")
# Visualize residual distribution with RMSE and R-squared
perf_exp.visualize()
# Access raw metrics
data = perf_exp.data()
print(f"RMSE: {data['rmse']:.4f}")
print(f"R-squared: {data['r2']:.4f}")
print(f"MAE: {data['mae']:.4f}")
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment