Skip to content

Commit

Permalink
Specify predict index in inference class
Browse files Browse the repository at this point in the history
  • Loading branch information
KristinaUlicna committed Sep 12, 2023
1 parent 5c60614 commit b85d6e5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 192 deletions.
20 changes: 13 additions & 7 deletions grace/evaluation/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def set_node_and_edge_probabilities(self, G: nx.Graph):
prediction = (int(e_pred[e_idx].item()), e_probabs[e_idx].numpy())
edge[-1][GraphAttrs.EDGE_PREDICTION] = prediction

def visualise_model_performance_on_test_graph(self, G: nx.Graph):
def visualise_model_performance_on_graph(
self, G: nx.Graph, positive_class: int = 1
):
# Prep the data & plot them:
node_true = np.array(
[
Expand Down Expand Up @@ -92,14 +94,18 @@ def visualise_model_performance_on_test_graph(self, G: nx.Graph):
)

# Unify the inputs - get the predictions scores for TP class:
filter_mask = node_true <= 1
node_pred = node_pred[filter_mask]
filter_mask = np.logical_or(
node_true == 0, node_true == positive_class
)
node_true = node_true[filter_mask]
node_pred = node_pred[filter_mask]
node_probabs = node_probabs[filter_mask]

filter_mask = edge_true <= 1
edge_pred = edge_pred[filter_mask]
filter_mask = np.logical_or(
edge_true == 0, edge_true == positive_class
)
edge_true = edge_true[filter_mask]
edge_pred = edge_pred[filter_mask]
edge_probabs = edge_probabs[filter_mask]

# Compute & return accuracy:
Expand All @@ -111,8 +117,8 @@ def visualise_model_performance_on_test_graph(self, G: nx.Graph):
plot_confusion_matrix_tiles(node_pred, edge_pred, node_true, edge_true)

areas_under_curves_metrics(
node_probabs[:, 1],
edge_probabs[:, 1],
node_probabs[:, positive_class],
edge_probabs[:, positive_class],
node_true,
edge_true,
figsize=(10, 4),
Expand Down
204 changes: 19 additions & 185 deletions notebooks/infer_predictions.ipynb

Large diffs are not rendered by default.

0 comments on commit b85d6e5

Please sign in to comment.