-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
150 lines (101 loc) · 2.87 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
---
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%"
)
```
<img src="hex/hexsticker.png" align="right" height="200"/>
# tsdataleaks
![CRAN status](https://www.r-pkg.org/badges/version/tsdataleaks)](https://CRAN.R-project.org/package=tsdataleaks)
R Package for detecting data leakages in time series forecasting competitions.
<img src="paper/poster.png" align="center"/>
## Installation
<!--You can install the released version of tsdataleaks from --> <!-- [CRAN](https://CRAN.R-project.org) with: -->
<!--
``` r
install.packages("tsdataleaks")
```
-->
The development version from [GitHub](https://github.com/) with:
```r
install.packages("tsdataleaks")
library(tsdataleaks)
```
or
``` r
# install.packages("devtools")
devtools::install_github("thiyangt/tsdataleaks")
library(tsdataleaks)
```
## Example
To demonstrate the package functions, I created a small data set with 4 time series.
```{r example, comment=NA, warning=FALSE, message=FALSE}
set.seed(2020)
a <- rnorm(15)
d <- rnorm(10)
lst <- list(
a = a,
b = c(a[10:15]+rep(8,6), rnorm(10), a[1:5], a[1:5]),
c = c(rnorm(10), -a[1:5]),
d = d,
e = d)
```
## `find_dataleaks`: Exploit data leaks
```{r, comment=NA, message=FALSE, warning=FALSE}
library(tsdataleaks)
library(magrittr)
library(tidyverse)
library(viridis)
# h - I assume test period length is 5 and took that as wind size, h.
f1 <- find_dataleaks(lstx = lst, h=5, cutoff=1)
f1
```
Interpretation: The first element in the list means the last 5 observations of the time series `a` correlates with time series `b` observarion from 2 to 6.
## `viz_dataleaks`: Visualise the data leaks
```{r, comment=NA, message=FALSE, warning=FALSE}
viz_dataleaks(f1)
```
## `reason_dataleaks`
Display the reasons for data leaks and evaluate usefulness of data leaks towards the winning of the competition
```{r, comment=NA, message=FALSE, warning=FALSE}
r1 <- reason_dataleaks(lstx = lst, finddataleaksout = f1, h=5)
r1
```
# A list without naming element
```{r, warning=FALSE, message=FALSE}
a = rnorm(15)
lst <- list(
a,
c(a[10:15], rnorm(10), a[1:5], a[1:5]),
c(rnorm(10), a[1:5])
)
f1 <- find_dataleaks(lst, h=5)
```
```{r, warning=FALSE, message=FALSE}
viz_dataleaks(f1)
```
```{r, warning=FALSE, message=FALSE}
reason_dataleaks(lst, f1, h=5)
```
# Application to M-Competition data
## M1 Competition - Yearly data
```{r, warning=FALSE, message=FALSE}
library(Mcomp)
data("M1")
M1Y <- subset(M1, "yearly")
M1Y_x <- lapply(M1Y, function(temp){temp$x})
m1y_f1 <- find_dataleaks(M1Y_x, h=6, cutoff = 1)
m1y_f1
```
```{r, warning=FALSE, message=FALSE}
viz_dataleaks(m1y_f1)
```
```{r, warning=FALSE, message=FALSE, fig.width=12}
reason_dataleaks(M1Y_x, m1y_f1, h=6, ang=90)
```