Hi,
first of all, I would like to say that Dalex is a very good package and there are many models available for the explanation that would otherwise be very difficult to include on their own.
Is it normal that the SHAP plot takes a long time? I myself did not get it to show the original SHAP plot.
Using 2000 background data samples could cause slower run times. Consider using shap.sample(data, K) or shap.kmeans(data, K) to summarize the background as K samples.
0%| | 4/1000 [08:41<35:50:59, 129.58s/it]
My Code:
#%%
from pycaret.datasets import get_data
df = get_data("bank")
#%%
import pycaret.classification as pycc
clf1 = pycc.setup(df, target = 'deposit', session_id=123, verbose= False, silent = True, use_gpu=False)
#%%
X = pycc.get_config('X').reset_index(drop=True)
y = pycc.get_config('y').reset_index(drop=True)
X_train = pycc.get_config('X_train').reset_index(drop=True)
X_test = pycc.get_config('X_test').reset_index(drop=True)
y_train = pycc.get_config('y_train').reset_index(drop=True)
y_test = pycc.get_config('y_test').reset_index(drop=True)
#%%%
import dalex as dx
dx.version
#%%
n, p = X_train.shape
#%%
METRICS = [
# keras.metrics.TruePositives(name='tp'),
# keras.metrics.FalsePositives(name='fp'),
# keras.metrics.TrueNegatives(name='tn'),
# keras.metrics.FalseNegatives(name='fn'),
tf.keras.metrics.BinaryAccuracy(name='accuracy'),
# keras.metrics.Precision(name='precision'),
tf.keras.metrics.Recall(name='recall'),
# keras.metrics.AUC(name='auc'),
]
tf.random.set_seed(11)
normalizer = tf.keras.layers.experimental.preprocessing.Normalization(input_shape=[p,])
normalizer.adapt(X.to_numpy())
model = tf.keras.Sequential([
normalizer,
tf.keras.Input(shape=(p,)),
tf.keras.layers.Dense(p2, activation='relu'),
# tf.keras.layers.Dense(p3, activation='relu'),
# tf.keras.layers.Dense(p3, activation='relu'),
# tf.keras.layers.Dense(p2, activation='relu'),
tf.keras.layers.Dense(p, activation='relu'),
tf.keras.layers.Dense(1, activation='sigmoid')
])
model.compile(
optimizer=tf.keras.optimizers.Adam(0.001),
loss=tf.keras.losses.BinaryCrossentropy(from_logits=True),
metrics=METRICS
)
model.summary()
#%%
import numpy as np
from sklearn.utils import class_weight
class_weight = class_weight.compute_class_weight('balanced',np.unique(y),y)
class_weight = dict(enumerate(class_weight))
class_weight
#%%
model.fit(X_train, y_train,
batch_size=int(n/10),
epochs=100,
class_weight = class_weight,
verbose=True)
#%%
import dalex as dx
dx.version
#%%
explainer = dx.Explainer(
model = model,
data = X_test[:2000],
y = y_test[:2000],
model_type= "classification")
#%%
explainer.model_performance()
#%%
explainer.model_parts().plot()
#%%
explainer.model_parts(type='shap_wrapper').plot()
%%
Hi,
first of all, I would like to say that Dalex is a very good package and there are many models available for the explanation that would otherwise be very difficult to include on their own.
Is it normal that the SHAP plot takes a long time? I myself did not get it to show the original SHAP plot.
Using 2000 background data samples could cause slower run times. Consider using shap.sample(data, K) or shap.kmeans(data, K) to summarize the background as K samples.
0%| | 4/1000 [08:41<35:50:59, 129.58s/it]
My Code:
#%%
from pycaret.datasets import get_data
df = get_data("bank")
#%%
import pycaret.classification as pycc
clf1 = pycc.setup(df, target = 'deposit', session_id=123, verbose= False, silent = True, use_gpu=False)
#%%
X = pycc.get_config('X').reset_index(drop=True)
y = pycc.get_config('y').reset_index(drop=True)
X_train = pycc.get_config('X_train').reset_index(drop=True)
X_test = pycc.get_config('X_test').reset_index(drop=True)
y_train = pycc.get_config('y_train').reset_index(drop=True)
y_test = pycc.get_config('y_test').reset_index(drop=True)
#%%%
import dalex as dx
dx.version
#%%
n, p = X_train.shape
#%%
METRICS = [
# keras.metrics.TruePositives(name='tp'),
# keras.metrics.FalsePositives(name='fp'),
# keras.metrics.TrueNegatives(name='tn'),
# keras.metrics.FalseNegatives(name='fn'),
tf.keras.metrics.BinaryAccuracy(name='accuracy'),
# keras.metrics.Precision(name='precision'),
tf.keras.metrics.Recall(name='recall'),
# keras.metrics.AUC(name='auc'),
]
tf.random.set_seed(11)
normalizer = tf.keras.layers.experimental.preprocessing.Normalization(input_shape=[p,])
normalizer.adapt(X.to_numpy())
model = tf.keras.Sequential([
normalizer,
tf.keras.Input(shape=(p,)),
tf.keras.layers.Dense(p2, activation='relu'),
# tf.keras.layers.Dense(p3, activation='relu'),
# tf.keras.layers.Dense(p3, activation='relu'),
# tf.keras.layers.Dense(p2, activation='relu'),
tf.keras.layers.Dense(p, activation='relu'),
tf.keras.layers.Dense(1, activation='sigmoid')
])
model.compile(
optimizer=tf.keras.optimizers.Adam(0.001),
loss=tf.keras.losses.BinaryCrossentropy(from_logits=True),
metrics=METRICS
)
model.summary()
#%%
import numpy as np
from sklearn.utils import class_weight
class_weight = class_weight.compute_class_weight('balanced',np.unique(y),y)
class_weight = dict(enumerate(class_weight))
class_weight
#%%
model.fit(X_train, y_train,
batch_size=int(n/10),
epochs=100,
class_weight = class_weight,
verbose=True)
#%%
import dalex as dx
dx.version
#%%
explainer = dx.Explainer(
model = model,
data = X_test[:2000],
y = y_test[:2000],
model_type= "classification")
#%%
explainer.model_performance()
#%%
explainer.model_parts().plot()
#%%
explainer.model_parts(type='shap_wrapper').plot()
%%