Interpret-Core
Interpret-Core is the minimal dependency core system for the InterpretML library, providing tools to fit inherently interpretable models like Explainable Boosting Machines (EBMs) and explain black-box machine learning models. It is currently at version 0.7.8 and maintains an active release cadence with frequent updates.
Warnings
- breaking The shape of the `bags` parameter in EBMs was changed from (n_outer_bags, n_samples) to (n_samples, n_outer_bags). In v0.7.0, the old format issued a warning and was accepted, but this behavior may be fully deprecated or removed in future major versions.
- breaking The `ComputeProvider` abstraction was removed in v0.7.3, simplifying the interface. Code relying on this abstraction will break.
- gotcha Older versions of `interpret-core` (prior to v0.7.4) had incompatibilities with `scikit-learn` versions 1.8 and above, specifically due to changes in `is_classifier` and `is_regressor` only accepting valid estimators.
- gotcha When using NumPy arrays as input to explainers, feature names might not appear in visualizations. This occurs because NumPy arrays lack inherent column names.
- gotcha For `ExplainableBoostingClassifier`, the y-axis values in the generated global explanation graphs are in 'logit' space, not direct probabilities. This requires careful interpretation for classification tasks.
Install
-
pip install interpret-core -
pip install interpret-core[required,ebm,plotly,dash]
Imports
- ExplainableBoostingClassifier
from interpret.glassbox import ExplainableBoostingClassifier
- ExplainableBoostingRegressor
from interpret.glassbox import ExplainableBoostingRegressor
- show
from interpret import show
Quickstart
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from interpret.glassbox import ExplainableBoostingClassifier
from interpret import show
# Generate some synthetic data
np.random.seed(0)
X = pd.DataFrame({
'feature_a': np.random.rand(100) * 10,
'feature_b': np.random.randint(0, 3, 100).astype(str),
'feature_c': np.random.randn(100)
})
y = (X['feature_a'] + (X['feature_b'].astype(int) * 2) + np.random.randn(100) > 10).astype(int)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Initialize and fit an Explainable Boosting Machine (EBM)
ebm = ExplainableBoostingClassifier(random_state=42)
ebm.fit(X_train, y_train)
# Get global explanations (feature importances and shapes)
ebm_global = ebm.explain_global()
# In a notebook environment, you would call show(ebm_global) to visualize
# For script execution, we can print summary or a representation of the explanation
print(f"Global Explanation for EBM:\n{ebm_global.data()}")
# Get local explanations for a specific sample
ebm_local = ebm.explain_local(X_test[:1], y_test[:1])
print(f"\nLocal Explanation for first test sample:\n{ebm_local.data()}")