def test_pickle_unpickle_mimic_explainer_classification(self, surrogate_model): x_train, x_test, y_train, _, feature_names, target_names = create_scikit_cancer_data() model = create_sklearn_svm_classifier(x_train, y_train) model_task = ModelTask.Unknown surrogate_model = surrogate_model explainer = MimicExplainer(model, x_train, surrogate_model, features=feature_names, model_task=model_task, classes=target_names) self._verify_explanations(explainer, x_test, get_mimic_method(surrogate_model)) recovered_explainer = self.pickle_unpickle_explainer(explainer) self._verify_explanations(recovered_explainer, x_test, get_mimic_method(surrogate_model))
def test_pickle_unpickle_mimic_explainer_regression(self, surrogate_model): num_features = 100 num_rows = 1000 test_size = 0.2 X, y = make_regression(n_samples=num_rows, n_features=num_features) x_train, x_test, y_train, _ = train_test_split(X, y, test_size=test_size, random_state=42) model = LinearRegression(normalize=True) model.fit(x_train, y_train) surrogate_model = surrogate_model explainer = MimicExplainer(model, x_train, surrogate_model) self._verify_explanations(explainer, x_test, get_mimic_method(surrogate_model)) recovered_explainer = self.pickle_unpickle_explainer(explainer) self._verify_explanations(recovered_explainer, x_test, get_mimic_method(surrogate_model))