Skip to content

Commit

Permalink
Create ExplainableAI.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Jul 5, 2024
1 parent 1a31f28 commit 55fb9f3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .ai/models/ExplainableAI.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 55fb9f3

Please sign in to comment.