Breast Cancer - XAI Course
unknown
python
a year ago
1.1 kB
22
Indexable
#this method should be added in the class of DiseaseClassifier def predict_proba(self, x): with torch.no_grad(): x = torch.tensor(x, dtype=torch.float32) pred = torch.nn.functional.softmax(self.forward(x).cpu().detach()) return np.array(pred) #LORE bbox = sklearn_classifier_wrapper(model) explainer = LoreTabularExplainer(bbox) inst_list = X_train[100:101] #list of lists inst_list[0] #list -- to give it to the explainer target = "diagnosis" explainer = LoreTabularExplainer(bbox) config = {'neigh_type':'rndgen', 'size':1000, 'ocr':0.1, 'ngen':10} explainer.fit(data, target, config) exp = explainer.explain(inst_list[0]) print(exp) exp.plotRules() exp.plotCounterfactualRules() #These two lines will give us rules and counterfactual rules. #LIME feature_names = data.columns explainer = lime.lime_tabular.LimeTabularExplainer(X_train, feature_names = feature_names) exp = explainer.explain_instance(inst_list[0], bbox.predict_proba) exp.show_in_notebook(show_table=True, show_all=False)
Editor is loading...
Leave a Comment