forked from business-science/modeltime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdials-prophet_params.R
159 lines (146 loc) · 4.53 KB
/
dials-prophet_params.R
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
151
152
153
154
155
156
#' Tuning Parameters for Prophet Models
#'
#' @inheritParams dials::learn_rate
#' @param values A character string of possible values.
#'
#' @details
#' The main parameters for Prophet models are:
#'
#' - `growth`: The form of the trend: "linear", or "logistic".
#' - `changepoint_num`: The maximum number of trend changepoints allowed when modeling the trend
#' - `changepoint_range`: The range affects how close the changepoints can go to the end of the time series.
#' The larger the value, the more flexible the trend.
#' - Yearly, Weekly, and Daily Seasonality:
#' - _Yearly_: `seasonality_yearly` - Useful when seasonal patterns appear year-over-year
#' - _Weekly_: `seasonality_weekly` - Useful when seasonal patterns appear week-over-week (e.g. daily data)
#' - _Daily_: `seasonality_daily` - Useful when seasonal patterns appear day-over-day (e.g. hourly data)
#' - `season`:
#' - The form of the seasonal term: "additive" or "multiplicative".
#' - See [season()].
#' - "Prior Scale": Controls flexibility of
#' - _Changepoints:_ `prior_scale_changepoints`
#' - _Seasonality:_ `prior_scale_seasonality`
#' - _Holidays:_ `prior_scale_holidays`
#' - The `log10_trans()` converts priors to a scale from 0.001 to 100,
#' which effectively weights lower values more heavily than larger values.
#'
#'
#'
#' @examples
#'
#' growth()
#'
#' changepoint_num()
#'
#' season()
#'
#' prior_scale_changepoints()
#'
#' @name prophet_params
#' @export
#' @rdname prophet_params
growth <- function(values = c("linear", "logistic")) {
dials::new_qual_param(
type = c("character"),
values = values,
default = "linear",
label = c(growth = "Growth Trend"),
finalize = NULL
)
}
#' @export
#' @rdname prophet_params
changepoint_num <- function(range = c(0L, 50L), trans = NULL) {
dials::new_quant_param(
type = "integer",
range = range,
inclusive = c(TRUE, TRUE),
trans = trans,
label = c(changepoint_num = "Number of Possible Trend Changepoints"),
finalize = NULL
)
}
#' @export
#' @rdname prophet_params
changepoint_range <- function(range = c(0.6, 0.9), trans = NULL) {
dials::new_quant_param(
type = "double",
range = range,
inclusive = c(TRUE, TRUE),
trans = trans,
label = c(changepoint_range = "Range of Trend Changepoints"),
finalize = NULL
)
}
#' @export
#' @rdname prophet_params
seasonality_yearly <- function(values = c(TRUE, FALSE)) {
dials::new_qual_param(
type = c("logical"),
values = values,
default = TRUE,
label = c(seasonality_yearly = "Use Yearly Seasonality"),
finalize = NULL
)
}
#' @export
#' @rdname prophet_params
seasonality_weekly <- function(values = c(TRUE, FALSE)) {
dials::new_qual_param(
type = c("logical"),
values = values,
default = TRUE,
label = c(seasonality_weekly = "Use Weekly Seasonality"),
finalize = NULL
)
}
#' @export
#' @rdname prophet_params
seasonality_daily <- function(values = c(TRUE, FALSE)) {
dials::new_qual_param(
type = c("logical"),
values = values,
default = TRUE,
label = c(seasonality_daily = "Use Daily Seasonality"),
finalize = NULL
)
}
#' @export
#' @rdname prophet_params
#' @importFrom scales log10_trans
prior_scale_changepoints <- function(range = c(-3, 2), trans = log10_trans()) {
dials::new_quant_param(
type = "double",
range = range,
inclusive = c(TRUE, TRUE),
trans = trans,
label = c(prior_scale_changepoints = "Prior Scale Changepoints"),
finalize = NULL
)
}
#' @export
#' @rdname prophet_params
#' @importFrom scales log10_trans
prior_scale_seasonality <- function(range = c(-3, 2), trans = log10_trans()) {
dials::new_quant_param(
type = "double",
range = range,
inclusive = c(TRUE, TRUE),
trans = trans,
label = c(prior_scale_seasonality = "Prior Scale Seasonality"),
finalize = NULL
)
}
#' @export
#' @rdname prophet_params
#' @importFrom scales log10_trans
prior_scale_holidays <- function(range = c(-3, 2), trans = log10_trans()) {
dials::new_quant_param(
type = "double",
range = range,
inclusive = c(TRUE, TRUE),
trans = trans,
label = c(prior_scale_holidays = "Prior Scale Holidays"),
finalize = NULL
)
}