Counterfactuals guided by prototypes on California housing dataset
pip install alibi[tensorflow]%matplotlib inline
import matplotlib.pyplot as plt
import 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 os
import numpy as np
import pandas as pd
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
from alibi.explainers import CounterfactualProto
print('TF version: ', tf.__version__)
print('Eager execution enabled: ', tf.executing_eagerly()) # FalseLoad and prepare California housing dataset
MedInc
HouseAge
AveRooms
AveBedrms
Population
AveOccup
Latitude
Longitude
Train model
Generate counterfactual guided by the nearest class prototype
MedInc
HouseAge
AveRooms
AveBedrms
Population
AveOccup
Latitude
Longitude
MedInc
HouseAge
AveRooms
AveBedrms
Population
AveOccup
Latitude
Longitude
PreviousCounterfactual explanations with ordinally encoded categorical variablesNextCounterfactuals guided by prototypes on MNIST
Last updated
Was this helpful?

