Last active
September 23, 2022 05:47
-
-
Save tomonori-masui/41cfcf5f0ebb4f46811cd1dfb5aaa351 to your computer and use it in GitHub Desktop.
Training graph anomaly detector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pygod.models import DOMINANT | |
| from sklearn.metrics import roc_auc_score, average_precision_score | |
| def train_anomaly_detector(model, graph): | |
| return model.fit(graph) | |
| def eval_anomaly_detector(model, graph): | |
| outlier_scores = model.decision_function(graph) | |
| auc = roc_auc_score(graph.y.numpy(), outlier_scores) | |
| ap = average_precision_score(graph.y.numpy(), outlier_scores) | |
| print(f'AUC Score: {auc:.3f}') | |
| print(f'AP Score: {ap:.3f}') | |
| graph.y = graph.y.bool() | |
| model = DOMINANT() | |
| model = train_anomaly_detector(model, graph) | |
| eval_anomaly_detector(model, graph) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment