maltese
maltese copied to clipboard
Forecasting horizont argument
I am wondering if it would make sense an horizon parameter in the mlts_transform function.
An example application would be predicting the next 7 days in a daily time series using a multi-target regression model.
The idea would be to do something like this in the current output:
library(maltese)
library(dplyr)
mlts <- mlts_transform(
r_enwiki, date, pageviews,
p = 7, # how many previous points of data to use as features
granularity = "day", # optional, can be automatically detected,
extras = TRUE, extrasAsFactors = TRUE # FALSE by default :D
)
mlts <- mlts %>% mutate(
y_1 = lead(y, n = 1, order_by = dt),
y_2 = lead(y, n = 2, order_by = dt),
y_3 = lead(y, n = 3, order_by = dt)
)
str(mlts)
'data.frame': 587 obs. of 17 variables:
$ dt : POSIXct, format: "2015-10-08" "2015-10-09" "2015-10-10" "2015-10-11" ...
$ y : num 3278 2886 1692 1902 3030 ...
$ mlts_extras_monthday: Ord.factor w/ 31 levels "1"<"2"<"3"<"4"<..: 8 9 10 11 12 13 14 15 16 17 ...
$ mlts_extras_weekday : Ord.factor w/ 7 levels "Monday"<"Tuesday"<..: 4 5 6 7 1 2 3 4 5 6 ...
$ mlts_extras_week : Ord.factor w/ 53 levels "1"<"2"<"3"<"4"<..: 41 41 41 41 41 41 41 42 42 42 ...
$ mlts_extras_month : Ord.factor w/ 12 levels "January"<"February"<..: 10 10 10 10 10 10 10 10 10 10 ...
$ mlts_extras_year : Ord.factor w/ 3 levels "2015"<"2016"<..: 1 1 1 1 1 1 1 1 1 1 ...
$ mlts_lag_1 : num 3385 3278 2886 1692 1902 ...
$ mlts_lag_2 : num 3695 3385 3278 2886 1692 ...
$ mlts_lag_3 : num 3041 3695 3385 3278 2886 ...
$ mlts_lag_4 : num 1540 3041 3695 3385 3278 ...
$ mlts_lag_5 : num 1431 1540 3041 3695 3385 ...
$ mlts_lag_6 : num 2575 1431 1540 3041 3695 ...
$ mlts_lag_7 : num 3072 2575 1431 1540 3041 ...
$ y_1 : num 2886 1692 1902 3030 3245 ...
$ y_2 : num 1692 1902 3030 3245 3313 ...
$ y_3 : num 1902 3030 3245 3313 3133 ...
Let me know what you think! I could work on a PR If you think it would be useful!
Ooooh, that's a neat idea. I like it! If you'd like to make a PR for this that'd be great!
btw I think for consistency – and to indicate that these are maltese-created columns – the names would need to be prefixed with mlts_lead_