# Harbinger Package
# version 1.0.777
source("https://raw.githubusercontent.com/cefet-rj-dal/harbinger/master/jupyter.R")
#loading Harbinger
load_library("daltoolbox")
load_library("harbinger")
Loading required package: daltoolbox Registered S3 method overwritten by 'quantmod': method from as.zoo.data.frame zoo Attaching package: ‘daltoolbox’ The following object is masked from ‘package:base’: transform Loading required package: harbinger
#loading the example database
data(examples_anomalies)
#Using the simple time series
dataset <- examples_anomalies$simple
head(dataset)
serie | event | |
---|---|---|
<dbl> | <lgl> | |
1 | 1.0000000 | FALSE |
2 | 0.9689124 | FALSE |
3 | 0.8775826 | FALSE |
4 | 0.7316889 | FALSE |
5 | 0.5403023 | FALSE |
6 | 0.3153224 | FALSE |
#ploting the time series
plot_ts(x = 1:length(dataset$serie), y = dataset$serie)
# establishing hanr_fft method
model <- hanr_fft()
# fitting the model
model <- fit(model, dataset$serie)
# making detections
detection <- detect(model, dataset$serie)
# filtering detected events
print(detection |> dplyr::filter(event==TRUE))
idx event type 1 50 TRUE anomaly
# evaluating the detections
evaluation <- evaluate(model, detection$event, dataset$event)
print(evaluation$confMatrix)
event detection TRUE FALSE TRUE 1 0 FALSE 0 100
# ploting the results
grf <- har_plot(model, dataset$serie, detection, dataset$event)
plot(grf)