# 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_chow()
# 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 changepoint
# 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)