@@ -48,13 +48,9 @@ package. In the future, we plan to support more forecasting learners.
4848
4949``` r
5050library(mlr3forecast )
51- # > Loading required package: mlr3
5251
5352task = tsk(" airpassengers" )
5453learner = lrn(" fcst.auto_arima" )$ train(task )
55- # > Registered S3 method overwritten by 'quantmod':
56- # > method from
57- # > as.zoo.data.frame zoo
5854prediction = learner $ predict(task , 140 : 144 )
5955prediction $ score(msr(" regr.rmse" ))
6056# > regr.rmse
@@ -103,32 +99,32 @@ prediction = flrn$predict_newdata(newdata, task)
10399prediction
104100# > <PredictionRegr> for 3 observations:
105101# > row_ids truth response
106- # > 1 NA 434.9439
107- # > 2 NA 439.1822
108- # > 3 NA 458.6453
102+ # > 1 NA 436.1867
103+ # > 2 NA 437.4089
104+ # > 3 NA 456.8410
109105prediction = flrn $ predict(task , 142 : 144 )
110106prediction
111107# > <PredictionRegr> for 3 observations:
112108# > row_ids truth response
113- # > 1 461 455.2556
114- # > 2 390 411.4701
115- # > 3 432 432.2286
109+ # > 1 461 459.1495
110+ # > 2 390 414.8433
111+ # > 3 432 430.2693
116112prediction $ score(msr(" regr.rmse" ))
117113# > regr.rmse
118- # > 12.83247
114+ # > 14.41767
119115
120116flrn = ForecastLearner $ new(lrn(" regr.ranger" ), 1 : 12 )
121117resampling = rsmp(" forecast_holdout" , ratio = 0.9 )
122118rr = resample(task , flrn , resampling )
123119rr $ aggregate(msr(" regr.rmse" ))
124120# > regr.rmse
125- # > 50.76601
121+ # > 48.97126
126122
127123resampling = rsmp(" forecast_cv" )
128124rr = resample(task , flrn , resampling )
129125rr $ aggregate(msr(" regr.rmse" ))
130126# > regr.rmse
131- # > 26.06017
127+ # > 25.19211
132128```
133129
134130Or with some feature engineering using mlr3pipelines:
@@ -150,7 +146,7 @@ glrn = as_learner(graph %>>% flrn)$train(task)
150146prediction = glrn $ predict(task , 142 : 144 )
151147prediction $ score(msr(" regr.rmse" ))
152148# > regr.rmse
153- # > 15.6575
149+ # > 15.58057
154150```
155151
156152### Example: forecasting electricity demand
@@ -159,22 +155,7 @@ prediction$score(msr("regr.rmse"))
159155library(mlr3learners )
160156library(mlr3pipelines )
161157
162- task = tsibbledata :: vic_elec | >
163- as.data.table() | >
164- setnames(tolower ) | >
165- _[
166- year(time ) == 2014L ,
167- .(
168- demand = sum(demand ) / 1e3 ,
169- temperature = max(temperature ),
170- holiday = any(holiday )
171- ),
172- by = date
173- ] | >
174- as_task_fcst(
175- id = " vic_elec" , target = " demand" , order = " date" , frequency = " daily"
176- )
177-
158+ task = tsk(" electricity" )
178159graph = ppl(" convert_types" , " Date" , " POSIXct" ) %>> %
179160 po(" datefeatures" ,
180161 param_vals = list (
@@ -195,13 +176,13 @@ prediction = glrn$predict_newdata(newdata, task)
195176prediction
196177# > <PredictionRegr> for 14 observations:
197178# > row_ids truth response
198- # > 1 NA 186.9592
199- # > 2 NA 191.3908
200- # > 3 NA 185.1543
179+ # > 1 NA 187595.7
180+ # > 2 NA 196608.6
181+ # > 3 NA 189152.0
201182# > --- --- ---
202- # > 12 NA 215.4734
203- # > 13 NA 219.6907
204- # > 14 NA 219.8203
183+ # > 12 NA 222400.3
184+ # > 13 NA 226494.8
185+ # > 14 NA 226568.4
205186```
206187
207188### Example: global forecasting (longitudinal data)
@@ -222,7 +203,7 @@ task = tsibbledata::aus_livestock |>
222203 target = " count" ,
223204 order = " month" ,
224205 key = " state" ,
225- frequency = " monthly"
206+ freq = " monthly"
226207 )
227208
228209graph = ppl(" convert_types" , " Date" , " POSIXct" ) %>> %
@@ -239,14 +220,14 @@ flrn = ForecastLearner$new(lrn("regr.ranger"), 1:3)$train(task)
239220prediction = flrn $ predict(task , 4460 : 4464 )
240221prediction $ score(msr(" regr.rmse" ))
241222# > regr.rmse
242- # > 22183.18
223+ # > 22604.48
243224
244225flrn = ForecastLearner $ new(lrn(" regr.ranger" ), 1 : 3 )
245226resampling = rsmp(" forecast_holdout" , ratio = 0.9 )
246227rr = resample(task , flrn , resampling )
247228rr $ aggregate(msr(" regr.rmse" ))
248229# > regr.rmse
249- # > 93061.55
230+ # > 92125.26
250231```
251232
252233### Example: global vs local forecasting
0 commit comments