skshift.ExplanationShiftDetector

class skshift.ExplanationShiftDetector(model, gmodel, algorithm: str = 'auto', masker: bool = False, data_masker: DataFrame | None = None)

Given a model, and two datasets (source,test), we want to know if the behaviour of the model is different bt train and test. We can do this by computing the shap values of the model on the two datasets, and then train a classifier to distinguish between the two datasets.

Example

>>> from sklearn.model_selection import train_test_split
>>> from sklearn.datasets import make_blobs
>>> from skshift import ExplanationShiftDetector
>>> from xgboost import XGBRegressor
>>> from sklearn.linear_model import LogisticRegression
>>> X, y = make_blobs(n_samples=2000, centers=2, n_features=5, random_state=0)
>>> X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.5, random_state=0)
>>> X_ood,y_ood = make_blobs(n_samples=1000, centers=1, n_features=5, random_state=0)
>>> detector = ExplanationShiftDetector(model=XGBRegressor(),gmodel=LogisticRegression())
>>> detector.fit(X_tr, y_tr, X_ood)
>>> roc_auc_score(y_new,detector.predict_proba(X_ood)[:,1])
>>> roc_auc_score(y_new,detector.predict_proba(X_te)[:,1])