ContextualAnomalyDetector calculates the anomaly score of a dataset using the notion of contexts conformed by facts and provides probabilistic abnormality scores.
data: Numerical vector with training and test dataset.
rest.period: Training period after an anomaly.
max.left.semicontexts: Number of semicontexts that should be maintained in memory.
max.active.neurons: Number of neurons of the model.
num.norm.value.bits: Granularity of the transformation into discrete values
base.threshold: Threshold to be considered an anomaly.
min.value: Minimum expected value.
max.value: Maximum expected value.
python.object: Python object for incremental processing.
lib: 0 to run the original python script, 1 to get the same results on all operating systems.
Returns
List - result: Data frame with anomaly.score and is.anomaly comparing the anomaly score with base.threshold.
python.object: ContextualAnomalyDetector Python object used in online anomaly detection
Details
data must be a numerical vector without NA values. threshold must be a numeric value between 0 and 1. If the anomaly score obtained for an observation is greater than the threshold, the observation will be considered abnormal. Requires hashlib (included in python installation) and bencode-python3 (which can be installed using pip) python libraries.
Examples
## Generate dataset.seed(100)n <-200x <- sample(1:100, n, replace =TRUE)x[70:90]<- sample(110:115,21, replace =TRUE)x[25]<-200x[150]<-170df <- data.frame(timestamp =1:n, value = x)## Calculate anomalies result <- ContextualAnomalyDetector(data = df$value, rest.period =10, base.threshold =0.9)## Plot results res <- cbind(df, result$result) PlotDetections(res, title ="CAD_OSE ANOMALY DETECTOR")