From 55fb9f3dd902f96965b449d3032c1761664fc663 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 5 Jul 2024 16:38:02 +0700 Subject: [PATCH] Create ExplainableAI.py --- .ai/models/ExplainableAI.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .ai/models/ExplainableAI.py diff --git a/.ai/models/ExplainableAI.py b/.ai/models/ExplainableAI.py new file mode 100644 index 0000000..59a94d1 --- /dev/null +++ b/.ai/models/ExplainableAI.py @@ -0,0 +1,16 @@ +import numpy as np +from lime.lime_tabular import LimeTabularExplainer + +class ExplainableAI: + def __init__(self, model, data): + self.model = model + self.data = data + self.explainer = LimeTabularExplainer(self.data, feature_names=self.data.columns, class_names=['class0', 'class1']) + + def explain_instance(self, instance): + exp = self.explainer.explain_instance(instance, self.model.predict_proba, num_features=5) + return exp.as_list() + + def explain_model(self): + exp = self.explainer.explain_model(self.model, self.data, num_features=5) + return exp.as_list()