NGBforecastCV {ngboostForecast} | R Documentation |
NGBoost forecasting model selection class
Description
It is a wrapper for the sklearn GridSearchCV with TimeSeriesSplit.
Methods
Public methods
Method new()
Initialize an NGBforecastCV model.
Usage
NGBforecastCV$new( Dist = NULL, Score = NULL, Base = NULL, natural_gradient = TRUE, n_estimators = as.integer(500), learning_rate = 0.01, minibatch_frac = 1, col_sample = 1, verbose = TRUE, verbose_eval = as.integer(100), tol = 1e-04, random_state = NULL )
Arguments
Dist
Assumed distributional form of
Y|X=x
. An output ofDist
function, e.g.Dist('Normal')
Score
Rule to compare probabilistic predictions to the observed data. A score from
Scores
function, e.g.Scores(score = "LogScore")
.Base
Base learner. An output of
sklearner
function, e.g.sklearner(module = "tree", class = "DecisionTreeRegressor", ...)
natural_gradient
Logical flag indicating whether the natural gradient should be used
n_estimators
The number of boosting iterations to fit
learning_rate
The learning rate
minibatch_frac
The percent subsample of rows to use in each boosting iteration
col_sample
The percent subsample of columns to use in each boosting iteration
verbose
Flag indicating whether output should be printed during fitting. If TRUE it will print logs.
verbose_eval
Increment (in boosting iterations) at which output should be printed
tol
Numerical tolerance to be used in optimization
random_state
Seed for reproducibility.
Returns
An NGBforecastCV object that can be fit.
Method tune()
Tune ngboosForecast.
Usage
NGBforecastCV$tune( y, max_lag = 5, xreg = NULL, seasonal = TRUE, K = frequency(y)/2 - 1, n_splits = NULL, train_loss_monitor = NULL, val_loss_monitor = NULL, early_stopping_rounds = NULL )
Arguments
y
A time series (ts) object
max_lag
Maximum number of lags
xreg
Optional. A numerical matrix of external regressors, which must have the same number of rows as y.
seasonal
Boolean. If
seasonal = TRUE
the fourier terms will be used for modeling seasonality.K
Maximum order(s) of Fourier terms, used only if
seasonal = TRUE
.n_splits
Number of splits. Must be at least 2.
train_loss_monitor
A custom score or set of scores to track on the training set during training. Defaults to the score defined in the NGBoost constructor. Please do not modify unless you know what you are doing.
val_loss_monitor
A custom score or set of scores to track on the validation set during training. Defaults to the score defined in the NGBoost constructor. Please do not modify unless you know what you are doing.
early_stopping_rounds
The number of consecutive boosting iterations during which the loss has to increase before the algorithm stops early.
test_size
The length of validation set. If it is NULL, then, it is automatically specified.
Returns
A named list of best parameters.
Method clone()
The objects of this class are cloneable with this method.
Usage
NGBforecastCV$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Author(s)
Resul Akay
References
https://stanfordmlgroup.github.io/ngboost/2-tuning.html
Examples
## Not run:
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)
params <- model$tune(y = AirPassengers,
seasonal = TRUE,
max_lag = 12,
xreg = NULL,
early_stopping_rounds = NULL,
n_splits = 4L)
params
## End(Not run)