Results of anomaly detection using STGAT-MAD#

from ice.anomaly_detection.datasets import AnomalyDetectionRiethTEP
from ice.anomaly_detection.models import STGAT_MAD
from sklearn.preprocessing import StandardScaler
import numpy as np
import pandas as pd

Download the dataset.

dataset = AnomalyDetectionRiethTEP()

Normalize the data.

scaler = StandardScaler()
dataset.df[dataset.train_mask] = scaler.fit_transform(dataset.df[dataset.train_mask])
dataset.df[dataset.test_mask] = scaler.transform(dataset.df[dataset.test_mask])

Create the GNN model.

model = STGAT_MAD(
    window_size=32, 
    num_epochs=30, 
    device='cuda',
    verbose=True,
    val_ratio=0.1,
    save_checkpoints=True,
    threshold_level=0.98
    )

Load the checkpoint.

model.load_checkpoint('stgat_anomaly_detection_epoch_30.tar')

Evaluate the model on the test data.

metrics = model.evaluate(dataset.df[dataset.test_mask], dataset.target[dataset.test_mask])
metrics
{'accuracy': 0.861279659277504,
 'true_positive_rate': [0.8352755],
 'false_positive_rate': [0.019435206422018347]}