def test_explain_model_imbalanced_classes(self, mimic_explainer): model = retrieve_model('unbalanced_model.pkl') x_train = retrieve_dataset('unbalanced_dataset.npz') model_predictions = model.predict(x_train) # Assert the model's predictions are skewed assert len(np.unique(model_predictions)) == 2 explainable_model = LGBMExplainableModel explainer = mimic_explainer(model, x_train, explainable_model, max_num_of_augmentations=10) global_explanation = explainer.explain_global(x_train, include_local=True) # There should be an explanation per feature assert len(global_explanation.global_importance_values) == 1585 # We should get back an explanation for each class assert len(global_explanation.local_importance_values) == 3 # Get the underlying multiclass model surrogate_predictions = explainer.surrogate_model.model.predict(x_train) assert len(np.unique(surrogate_predictions)) == 2 assert len(np.unique(model_predictions)) == 2 assert np.isclose(surrogate_predictions, model_predictions).all()
def preload_models(): for model_name in MODELS_NAMES: retrieve_model(model_name)