# 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_changepoints)
#Using the simple time series
dataset <- examples_changepoints$simple
head(dataset)
serie | event | |
---|---|---|
<dbl> | <lgl> | |
1 | 0.00 | FALSE |
2 | 0.25 | FALSE |
3 | 0.50 | FALSE |
4 | 0.75 | FALSE |
5 | 1.00 | FALSE |
6 | 1.25 | FALSE |
#ploting the time series
plot_ts(x = 1:length(dataset$serie), y = dataset$serie)
# establishing change point method
model <- hcp_pelt()
# 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 9 TRUE changepoint 2 19 TRUE changepoint 3 29 TRUE changepoint 4 39 TRUE changepoint 5 60 TRUE changepoint 6 71 TRUE changepoint 7 81 TRUE changepoint 8 91 TRUE changepoint
# evaluating the detections
evaluation <- evaluate(model, detection$event, dataset$event)
print(evaluation$confMatrix)
event detection TRUE FALSE TRUE 0 8 FALSE 1 92
# ploting the results
grf <- har_plot(model, dataset$serie, detection, dataset$event)
plot(grf)