class pygod.detector.ANOMALOUS(gamma=1.0, weight_decay=0.0, lr=0.004, epoch=100, gpu=-1, contamination=0.1, verbose=0)[source]#

Bases: Detector

A Joint Modeling Approach for Anomaly Detection on Attributed Networks

ANOMALOUS is an anomaly detector with CUR decomposition and residual analysis.


This detector is transductive only. Using predict with unseen data will train the detector from scratch.

See [PLL+18] for details.

  • gamma (float, optional) – Weight of node feature w.r.t. structure. Default: 1.

  • weight_decay (float, optional) – Weight decay (L2 penalty). Default: 0..

  • lr (float, optional) – Learning rate. Default: 0.004.

  • epoch (int, optional) – Maximum number of training epoch. Default: 100.

  • gpu (int) – GPU Index, -1 for using CPU. Default: -1.

  • contamination (float, optional) – Valid in (0., 0.5). The proportion of outliers in the data set. Used when fitting to define the threshold on the decision function. Default: 0.1.

  • verbose (int, optional) – Verbosity mode. Range in [0, 3]. Larger value for printing out more log information. Default: 0.

fit(data, label=None)[source]#

Fit detector with training data.

  • data ( – The training graph.

  • label (torch.Tensor, optional) – The optional outlier ground truth labels used to monitor the training progress. They are not used to optimize the unsupervised model. Default: None.


self – Fitted detector.

Return type:


predict(data=None, label=None, return_pred=True, return_score=False, return_prob=False, prob_method='linear', return_conf=False)#

Prediction for testing data using the fitted detector. Return predicted labels by default.

  • data (, optional) – The testing graph. If None, the training data is used. Default: None.

  • label (torch.Tensor, optional) – The optional outlier ground truth labels used for testing. Default: None.

  • return_pred (bool, optional) – Whether to return the predicted binary labels. The labels are determined by the outlier contamination on the raw outlier scores. Default: True.

  • return_score (bool, optional) – Whether to return the raw outlier scores. Default: False.

  • return_prob (bool, optional) – Whether to return the outlier probabilities. Default: False.

  • prob_method (str, optional) –

    The method to convert the outlier scores to probabilities. Two approaches are possible:

    1. 'linear': simply use min-max conversion to linearly transform the outlier scores into the range of [0,1]. The model must be fitted first.

    2. 'unify': use unifying scores, see [KKSZ11].

    Default: 'linear'.

  • return_conf (boolean, optional) – Whether to return the model’s confidence in making the same prediction under slightly different training sets. See [PVD20]. Default: False.


  • pred (torch.Tensor) – The predicted binary outlier labels of shape \(N\). 0 stands for inliers and 1 for outliers. Only available when return_label=True.

  • score (torch.Tensor) – The raw outlier scores of shape \(N\). Only available when return_score=True.

  • prob (torch.Tensor) – The outlier probabilities of shape \(N\). Only available when return_prob=True.

  • conf (torch.Tensor) – The prediction confidence of shape \(N\). Only available when return_conf=True.