Skip to content

Instantly share code, notes, and snippets.

@tomonori-masui
Last active September 23, 2022 05:47
Show Gist options
  • Select an option

  • Save tomonori-masui/41cfcf5f0ebb4f46811cd1dfb5aaa351 to your computer and use it in GitHub Desktop.

Select an option

Save tomonori-masui/41cfcf5f0ebb4f46811cd1dfb5aaa351 to your computer and use it in GitHub Desktop.
Training graph anomaly detector
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