Skip to content

Commit

Permalink
things has been changed
Browse files Browse the repository at this point in the history
  • Loading branch information
GiacomoAru committed Jan 8, 2024
1 parent 4a09d57 commit e82b32a
Show file tree
Hide file tree
Showing 21 changed files with 145,862 additions and 132,091 deletions.
18 changes: 3 additions & 15 deletions TASK_4/lime_irene.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_lime_importance_from_explanation(lime_explanation, prediction):
# - discretize_continuous = True (continuous features are discretized into quartiles)
# - discretizer = 'quartile'
# - sample_around_instance = False (sample from a normal centered on the mean of the feature data)
#
#
# Also to explain instances we will use deault parameters, i.e.:
# - num_samples = 5000, number of samples to generate
# - distance_metric = 'euclidean', distance metric to use for weights
Expand Down Expand Up @@ -273,12 +273,6 @@ def get_lime_importance_from_explanation(lime_explanation, prediction):
# %%
clf_names = [Classifiers.DT.value, Classifiers.RF.value, Classifiers.SVM.value, Classifiers.XGB.value, Classifiers.NN.value]

# %%
classifiers[Classifiers.NN.value].predict_proba(indicators_test_db_df[:10])

# %%
classifiers[Classifiers.RF.value].predict_proba(indicators_test_rb_df[:10])

# %%
positions_to_explain = selected_records_to_explain_df['positions'].to_list()
instance_names_to_explain = selected_records_to_explain_df['instance names'].to_list()
Expand All @@ -300,7 +294,7 @@ def get_lime_importance_from_explanation(lime_explanation, prediction):
clf_metrics = {}
for i in range(instances.shape[0]):
prediction = classifier.predict(instances[i].reshape(1,-1))[0]
if clf_name == Classifiers.SVM.value:
if clf_name == Classifiers.SVM.value or clf_name == Classifiers.NN.value:
prob = classifier.predict_proba(instances[i].reshape(1,-1))[0]
if prob[1] >= 0.5:
prediction = 1
Expand Down Expand Up @@ -331,12 +325,6 @@ def get_lime_importance_from_explanation(lime_explanation, prediction):

metrics_selected_records_df

# %%
explanation.local_exp[0]
# feature_importances = np.zeros(len(pred_explanation))
# for tuple in pred_explanation:
# feature_importances[tuple[0]] = tuple[1]

# %%
random_records_to_explain_df = pd.read_csv('../data/explanation_results/random_records_to_explain.csv', index_col=0)
positions_to_explain = random_records_to_explain_df['positions'].to_list()
Expand All @@ -357,7 +345,7 @@ def get_lime_importance_from_explanation(lime_explanation, prediction):
faithfulness = []
for i in range(instances.shape[0]):
prediction = classifier.predict(instances[i].reshape(1,-1))[0]
if clf_name == Classifiers.SVM.value:
if clf_name == Classifiers.SVM.value or clf_name == Classifiers.NN.value:
prob = classifier.predict_proba(instances[i].reshape(1,-1))[0]
if prob[1] >= 0.5:
prediction = 1
Expand Down
Loading

0 comments on commit e82b32a

Please sign in to comment.