## Warning: package 'dplyr' was built under R version 3.4.1
Either you try stable CRAN version
install.packages("cbar")
Or unstable development version
devtools::install_github("zedoul/cbar")
You’ll need to use library
to load as follows:
library(cbar)
cbar
is an R package for detecting anomaly in time-series data with Bayesian inference. Although there are many packages to detect anomaly in the world, relatively few packages provide functions for visually and/or analytically abstracting the output.
The cbar
package aims to provide simple-to-use functions for detecting anomaly, and abstracting the analysis output.
A minimal example would be like:
library(cbar)
.data <- mtcars
rownames(.data) <- NULL
datetime <- seq(from = Sys.time(), length.out = nrow(.data), by = "mins")
.data <- cbind(datetime = datetime, .data)
ref_session <- 1:16
mea_session <- 17:nrow(.data)
.cbar <- cbar(.data, ref_session, mea_session)
plot_ts(.cbar)
You may wonder why it uses reference
and measurement
instead of training
and testing
. In anomaly detection, espeically in telecommuncation field, performance reference period
refers a period which serves a basis for defining anomaly, and performance measurement period
refers the period during which performance parameters are measured.
If you hope to see the abstracted outcome, then:
summarise_session(.cbar)
## session n_anomaly n_total rate
## 1 reference 0 16 0.000
## 2 measurement 2 16 0.125
or you can just use print
function as follows:
print(.cbar)
## session n_anomaly n_total rate
## 1 reference 0 16 0.000
## 2 measurement 2 16 0.125
If you hope to see details of those anomalies:
summarise_anomaly(.cbar, .session = "measurement")
## datetime session y point_pred lower_bound upper_bound
## 1 2017-08-04 22:05:05 measurement 14.7 10.84784 6.444648 15.99999
## 2 2017-08-04 22:06:05 measurement 32.4 24.92361 20.835989 29.16468
## 3 2017-08-04 22:07:05 measurement 30.4 26.91552 21.680584 33.48467
## 4 2017-08-04 22:08:05 measurement 33.9 25.95228 20.768904 30.55843
## 5 2017-08-04 22:09:05 measurement 21.5 23.35713 18.680964 28.07237
## 6 2017-08-04 22:10:05 measurement 15.5 17.56335 12.994630 21.44423
## 7 2017-08-04 22:11:05 measurement 15.2 18.03868 13.713885 22.00692
## 8 2017-08-04 22:12:05 measurement 13.3 14.61334 9.386319 20.05820
## 9 2017-08-04 22:13:05 measurement 19.2 16.13331 11.881032 20.04780
## 10 2017-08-04 22:14:05 measurement 27.3 25.54004 20.693667 29.99246
## 11 2017-08-04 22:15:05 measurement 26.0 24.17099 19.134608 29.34844
## 12 2017-08-04 22:16:05 measurement 30.4 24.93561 18.375929 30.97176
## 13 2017-08-04 22:17:05 measurement 15.8 15.85823 6.979037 24.17541
## 14 2017-08-04 22:18:05 measurement 19.7 19.15798 11.114839 25.39482
## 15 2017-08-04 22:19:05 measurement 15.0 12.34801 2.335229 20.75310
## 16 2017-08-04 22:20:05 measurement 21.4 22.20520 18.018138 27.08729
## anomaly
## 1 FALSE
## 2 TRUE
## 3 FALSE
## 4 TRUE
## 5 FALSE
## 6 FALSE
## 7 FALSE
## 8 FALSE
## 9 FALSE
## 10 FALSE
## 11 FALSE
## 12 FALSE
## 13 FALSE
## 14 FALSE
## 15 FALSE
## 16 FALSE