Skip to content

Anomaly Detection

# define threshold
instances = 4 # 4%

# calculate densityes
densities = model.score_samples(X)

# calculate density threshold
density_threshold = np.percentile(densities, instances)

# reproduce the anomalies
anomalies = X[densities < densities_threshold]

For more examples, see the pyOD documentation. In particular:

  • predict_proba - predict the probability of a sample being an outlier.
  • predict - predict if a sample is an outlier or not.