-
Notifications
You must be signed in to change notification settings - Fork 5
/
explainer.py
37 lines (26 loc) · 1.14 KB
/
explainer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from sklearn_explain.reason_codes import explain_factory as expl
from sklearn_explain.reason_codes import settings as conf
# This is a model explainer designed for classifiers and regressors with continous inputs.
# Support for multiclass models and categorical inputs is also available.
# usage :
'''
clf = RandomForestClassifier().fit(X,y) # ... train any scikit-learn model
lExplainer = cModelScoreExplainer(clf).fit(X,y) #
reason_codes = lExplainer.explain(X_new)
'''
class cModelScoreExplainer:
def __init__(self , clf):
self.mModel = clf
self.mImplementation = None
self.mSettings = conf.cScoreExplainerConfig()
self.mDebug = True
def fit(self, X):
lFactory = expl.cScoreExplainerFactory()
self.mImplementation = lFactory.build_Explainer(self.mModel , self.mSettings)
return self.mImplementation.fit(X)
def explain(self, X):
assert(self.mImplementation is not None)
return self.mImplementation.explain(X)
def get_local_score_card(self, X):
assert(self.mImplementation is not None)
return self.mImplementation.get_local_score_card(X)