Contrastive Explanations Method (CEM) applied to Iris dataset
pip install alibi[tensorflow]!pip install seabornimport tensorflow as tf
tf.get_logger().setLevel(40) # suppress deprecation messages
tf.compat.v1.disable_v2_behavior() # disable TF2 behaviour as alibi code still relies on TF1 constructs
from tensorflow.keras.layers import Dense, Input
from tensorflow.keras.models import Model, load_model
from tensorflow.keras.utils import to_categorical
import matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import os
import pandas as pd
import seaborn as sns
from sklearn.datasets import load_iris
from alibi.explainers import CEM
print('TF version: ', tf.__version__)
print('Eager execution enabled: ', tf.executing_eagerly()) # FalseLoad and prepare Iris dataset
Define and train logistic regression model
Generate contrastive explanation with pertinent negative
Generate pertinent positive
Visualize PN and PP

Use numerical gradients in CEM
Last updated
Was this helpful?

