-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
executable file
·132 lines (98 loc) · 3.77 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
---
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%"
)
```
# ngboostForecast
<!-- badges: start -->
<!-- badges: end -->
The goal of ngboostForecast is to provide a tools for probabilistic forecasting by using Python's ngboost for R users.
## Installation
You can install the released version of ngboostForecast from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("ngboostForecast")
```
And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("Akai01/ngboostForecast")
```
## Example
This is a basic example which shows you how to solve a common problem:
```{r example}
library(ngboostForecast)
train = window(seatbelts, end = c(1983,12))
test = window(seatbelts, start = c(1984,1))
# without external variables with Ridge regression
model <- NGBforecast$new(Dist = Dist("LogNormal"),
Base = sklearner(module = "linear_model",
class = "Ridge"),
Score = Scores("LogScore"),
natural_gradient = TRUE,
n_estimators = 200,
learning_rate = 0.1,
minibatch_frac = 1,
col_sample = 1,
verbose = TRUE,
verbose_eval = 5,
tol = 1e-5)
model$fit(y = train[,2],
seasonal = TRUE,
max_lag = 12,
early_stopping_rounds = 10L)
fc <- model$forecast(h = 12, level = c(99,95,90, 80, 70, 60),
data_frame = FALSE)
autoplot(fc) + autolayer(test[,2])
```
# Tuning
## Set the parameters:
``` {r example2, echo = TRUE}
library(ngboostForecast)
dists <- list(Dist("Normal"))
base_learners <- list(sklearner(module = "tree", class = "DecisionTreeRegressor",
max_depth = 1),
sklearner(module = "tree", class = "DecisionTreeRegressor",
max_depth = 2),
sklearner(module = "tree", class = "DecisionTreeRegressor",
max_depth = 3),
sklearner(module = "tree", class = "DecisionTreeRegressor",
max_depth = 4),
sklearner(module = "tree", class = "DecisionTreeRegressor",
max_depth = 5),
sklearner(module = "tree", class = "DecisionTreeRegressor",
max_depth = 6),
sklearner(module = "tree", class = "DecisionTreeRegressor",
max_depth = 7))
scores <- list(Scores("LogScore"))
model <- NGBforecastCV$new(Dist = dists,
Base = base_learners,
Score = scores,
natural_gradient = TRUE,
n_estimators = list(10, 100),
learning_rate = list(0.1, 0.2),
minibatch_frac = list(0.1, 1),
col_sample = list(0.3),
verbose = FALSE,
verbose_eval = 100,
tol = 1e-5)
```
## Tune the model:
```{r example3, echo=TRUE, warning = FALSE, message = FALSE}
params <- model$tune(y = AirPassengers,
seasonal = TRUE,
max_lag = 12,
xreg = NULL,
early_stopping_rounds = NULL,
n_splits = 4L)
```
## Best parameters:
```{r eample4}
params
```