-
Notifications
You must be signed in to change notification settings - Fork 25
feat: add input nodes as evaluation baseline #372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
968bd09
7202a99
1b3be75
8ca0e9e
dda6264
d8a16fc
7f3c7f6
8492f70
9b8e31c
04ddc1f
e98d1e2
5e10e95
2004c9a
82fbfce
dcab781
a57ef19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -354,7 +354,7 @@ def edge_frequency_node_ensemble(node_table: pd.DataFrame, ensemble_files: list[ | |
| return node_ensembles_dict | ||
|
|
||
| @staticmethod | ||
| def precision_recall_curve_node_ensemble(node_ensembles: dict, node_table: pd.DataFrame, output_png: str | PathLike, | ||
| def precision_recall_curve_node_ensemble(node_ensembles: dict, node_table: pd.DataFrame, dataset_file: str, output_png: str | PathLike, | ||
| output_file: str | PathLike, aggregate_per_algorithm: bool = False): | ||
| """ | ||
| Plots precision-recall (PR) curves for a set of node ensembles evaluated against a gold standard. | ||
|
|
@@ -387,6 +387,34 @@ def precision_recall_curve_node_ensemble(node_ensembles: dict, node_table: pd.Da | |
| if not node_ensemble.empty: | ||
| y_true = [1 if node in gold_standard_nodes else 0 for node in node_ensemble['Node']] | ||
| y_scores = node_ensemble['Frequency'].tolist() | ||
|
|
||
| # TODO: add a new one here for y_scores_baseline where the sources and targets frequency are set to 1 | ||
| # set the scores for nodes in node_ensemble that are in both the gold_standard_nodes and sources/targets/prizes to 1.0 | ||
| # then make that into a new node_ensemble with altered values that are then plotted. | ||
|
|
||
| pickle = Evaluation.from_file(dataset_file) | ||
| prizes_df = pickle.get_node_columns(["sources", "targets", "prize"]) | ||
| prizes = set(prizes_df['NODEID']) | ||
| prize_gold_intersection = prizes & gold_standard_nodes | ||
| prize_node_ensemble_df = node_ensemble.copy() | ||
|
|
||
| # TODO what if the node_ensemble is all frequency = 0.0, that will be the new source/target/prize/ baseline? | ||
|
|
||
| # Set frequency to 1.0 for matching nodes | ||
| prize_node_ensemble_df.loc[ | ||
|
||
| prize_node_ensemble_df['Node'].isin(prize_gold_intersection), | ||
| 'Frequency' | ||
| ] = 1.0 | ||
| print(prize_node_ensemble_df) | ||
|
|
||
| y_scores_prizes = prize_node_ensemble_df['Frequency'].tolist() | ||
|
|
||
| precision_prizes, recall_prizes, thresholds_prizes = precision_recall_curve(y_true, y_scores_prizes) | ||
| plt.plot(recall_prizes, precision_prizes, color=color_palette[label], marker='o', linestyle=':', | ||
| label=f'{label.capitalize()} with prizes') | ||
|
|
||
|
|
||
|
|
||
| precision, recall, thresholds = precision_recall_curve(y_true, y_scores) | ||
| # avg precision summarizes a precision-recall curve as the weighted mean of precisions achieved at each threshold | ||
| avg_precision = average_precision_score(y_true, y_scores) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.