-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
103 lines (82 loc) · 2.34 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# datadriftR
<!-- badges: start -->
<!-- badges: end -->
A system designed for detecting data drift in streaming datasets, offering a suite of statistical methods to track variations in data behavior.
## Installation
```{r}
remotes::install_github("ugurdar/datadriftR@main")
```
## Examples
#### DDM
```{r example}
library(datadriftR)
# Generate a sample data stream of 1000 elements with approximately equal probabilities for 0 and 1
set.seed(123) # Setting a seed for reproducibility
data_part1 <- sample(c(0, 1), size = 500, replace = TRUE, prob = c(0.7, 0.3))
# Introduce a change in data distribution
data_part2 <- sample(c(0, 1), size = 500, replace = TRUE, prob = c(0.3, 0.7))
# Combine the two parts
data_stream <- c(data_part1, data_part2)
# Initialize the DDM object
ddm <- DDM$new()
# Iterate through the data stream
for (i in seq_along(data_stream)) {
ddm$add_element(data_stream[i])
if (ddm$change_detected) {
message(paste("Drift detected!", i))
} else if (ddm$warning_detected) {
# message(paste("Warning detected at position:", i))
}
}
```
#### EDDM
```{r}
eddm <- EDDM$new()
for (i in 1:length(data_stream)) {
eddm$add_element(data_stream[i])
if (eddm$change_detected) {
message(paste("Drift detected!",i))
} else if (eddm$warning_detected) {
# message(paste("Warning detected!",i))
}
}
```
#### HDDM-A
```{r}
hddm_a <- HDDM_A$new()
for(i in seq_along(data_stream)) {
hddm_a$add_element(data_stream[i])
if (hddm_a$warning_detected) {
cat(sprintf("Warning zone has been detected in data: %s - at index: %d\n", data_stream[i], i))
}
if (hddm_a$change_detected) {
cat(sprintf("Change has been detected in data: %s - at index: %d\n", data_stream[i], i))
hddm_a$reset() # Reset after detecting change
}
}
```
#### HDDM-W
```{r}
hddm_w_instance <- HDDM_W$new()
for(i in seq_along(data_stream)) {
hddm_w_instance$add_element(data_stream[i])
if(hddm_w_instance$warning_detected) {
cat(sprintf("Warning zone detected at index: %d\n", i))
}
if(hddm_w_instance$change_detected) {
cat(sprintf("Concept drift detected at index: %d\n", i))
}
}
```