| Title: | Probabilistic Time Series Forecasting |
| Version: | 0.1.1 |
| Description: | Probabilistic time series forecasting via Natural Gradient Boosting for Probabilistic Prediction. |
| License: | Apache License (≥ 2) |
| URL: | https://github.com/Akai01/ngboostForecast |
| BugReports: | https://github.com/Akai01/ngboostForecast/issues |
| Encoding: | UTF-8 |
| LazyData: | true |
| SystemRequirements: | Python (>= 3.6) |
| RoxygenNote: | 7.2.0 |
| Imports: | dplyr (≥ 1.0.7), forecast (≥ 8.15), magrittr (≥ 2.0.1), R6 (≥ 2.5.1) |
| Suggests: | ggplot2 (≥ 3.3.5), testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| Config/reticulate: | list( packages = list( list(package = 'importlib-metadata', pip = TRUE), list(package = 'ngboost', pip = TRUE)) ) |
| Depends: | R (≥ 3.6), reticulate (≥ 1.20) |
| NeedsCompilation: | no |
| Packaged: | 2022-08-06 10:57:52 UTC; akayr |
| Author: | Resul Akay [aut, cre] |
| Maintainer: | Resul Akay <resulakay1@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2022-08-06 11:30:08 UTC |
Pipe operator
Description
See magrittr::%>% for details.
See magrittr::%>% for details.
Usage
lhs %>% rhs
lhs %>% rhs
Value
Nothing
Assignment pipe operator
Description
See magrittr::%<>% for details.
Usage
lhs %<>% rhs
NGBoost distributions
Description
NGBoost distributions
Usage
Dist(
dist = c("Normal", "Bernoulli", "k_categorical", "StudentT", "Laplace", "Cauchy",
"Exponential", "LogNormal", "MultivariateNormal", "Poisson"),
k
)
Arguments
dist |
NGBoost distributions. One of the following:
|
k |
Used only with k_categorical and MultivariateNormal |
Value
An NGBoost Distribution object
NGBoost forecasting class
Description
The main forecasting class.
Value
An NGBforecast class
Methods
Public methods
Method new()
Initialize an NGBforecast model.
Usage
NGBforecast$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
DistAssumed distributional form of
Y|X=x. An output ofDistfunction, e.g.Dist('Normal')ScoreRule to compare probabilistic predictions to the observed data. A score from
Scoresfunction, e.g.Scores(score = "LogScore").BaseBase learner. An output of
sklearnerfunction, e.g.sklearner(module = "tree", class = "DecisionTreeRegressor", ...)natural_gradientLogical flag indicating whether the natural gradient should be used
n_estimatorsThe number of boosting iterations to fit
learning_rateThe learning rate
minibatch_fracThe percent subsample of rows to use in each boosting iteration
col_sampleThe percent subsample of columns to use in each boosting iteration
verboseFlag indicating whether output should be printed during fitting. If TRUE it will print logs.
verbose_evalIncrement (in boosting iterations) at which output should be printed
tolNumerical tolerance to be used in optimization
random_stateSeed for reproducibility.
Returns
An NGBforecast object that can be fit.
Method fit()
Fit the initialized model.
Usage
NGBforecast$fit( y, max_lag = 5, xreg = NULL, test_size = NULL, seasonal = TRUE, K = frequency(y)/2 - 1, train_loss_monitor = NULL, val_loss_monitor = NULL, early_stopping_rounds = NULL )
Arguments
yA time series (ts) object
max_lagMaximum number of lags
xregOptional. A numerical matrix of external regressors, which must have the same number of rows as y.
test_sizeThe length of validation set. If it is NULL, then, it is automatically specified.
seasonalBoolean. If
seasonal = TRUEthe fourier terms will be used for modeling seasonality.KMaximum order(s) of Fourier terms, used only if
seasonal = TRUE.train_loss_monitorA 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_monitorA 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_roundsThe number of consecutive boosting iterations during which the loss has to increase before the algorithm stops early.
Returns
NULL
Method forecast()
Forecast the fitted model
Usage
NGBforecast$forecast(h = 6, xreg = NULL, level = c(80, 95), data_frame = FALSE)
Arguments
hForecast horizon
xregA numerical vector or matrix of external regressors
levelConfidence level for prediction intervals
data_frameBool. If TRUE, forecast will be returned as a data.frame object, if FALSE it will return a forecast class. If TRUE,
autoplotwill function.
Method feature_importances()
Return the feature importance for all parameters in the distribution (the higher, the more important the feature).
Usage
NGBforecast$feature_importances()
Returns
A data frame
Method plot_feature_importance()
Plot feature importance
Usage
NGBforecast$plot_feature_importance()
Returns
A ggplot object
Method get_params()
Get parameters for this estimator.
Usage
NGBforecast$get_params(deep = TRUE)
Arguments
deepbool, default = TRUE If True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns
A named list of parameters.
Method clone()
The objects of this class are cloneable with this method.
Usage
NGBforecast$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Author(s)
Resul Akay
References
Duan, T et. al. (2019), NGBoost: Natural Gradient Boosting for Probabilistic Prediction.
Examples
## Not run:
library(ngboostForecast)
model <- NGBforecast$new(Dist = Dist("Normal"),
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 = 100,
tol = 1e-5)
model$fit(y = AirPassengers, seasonal = TRUE, max_lag = 12, xreg = NULL,
early_stopping_rounds = 10L)
fc <- model$forecast(h = 12, level = c(90, 80), xreg = NULL)
autoplot(fc)
## End(Not run)
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
DistAssumed distributional form of
Y|X=x. An output ofDistfunction, e.g.Dist('Normal')ScoreRule to compare probabilistic predictions to the observed data. A score from
Scoresfunction, e.g.Scores(score = "LogScore").BaseBase learner. An output of
sklearnerfunction, e.g.sklearner(module = "tree", class = "DecisionTreeRegressor", ...)natural_gradientLogical flag indicating whether the natural gradient should be used
n_estimatorsThe number of boosting iterations to fit
learning_rateThe learning rate
minibatch_fracThe percent subsample of rows to use in each boosting iteration
col_sampleThe percent subsample of columns to use in each boosting iteration
verboseFlag indicating whether output should be printed during fitting. If TRUE it will print logs.
verbose_evalIncrement (in boosting iterations) at which output should be printed
tolNumerical tolerance to be used in optimization
random_stateSeed 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
yA time series (ts) object
max_lagMaximum number of lags
xregOptional. A numerical matrix of external regressors, which must have the same number of rows as y.
seasonalBoolean. If
seasonal = TRUEthe fourier terms will be used for modeling seasonality.KMaximum order(s) of Fourier terms, used only if
seasonal = TRUE.n_splitsNumber of splits. Must be at least 2.
train_loss_monitorA 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_monitorA 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_roundsThe number of consecutive boosting iterations during which the loss has to increase before the algorithm stops early.
test_sizeThe 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
deepWhether 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)
Select a rule to compare probabilistic predictions to the observed data.
Description
Select a rule to compare probabilistic predictions to the observed data. A score from ngboost.scores, e.g. LogScore.
Usage
Scores(score = c("LogScore", "CRPS", "CRPScore", "MLE"))
Arguments
score |
A string. can be one of the following:
|
Value
A score class from ngboost.scores
Author(s)
Resul Akay
forecast package autolayer function
Description
See autolayer for details.
Usage
autolayer(object,...)
Value
A ggplot layer
See Also
forecast package autoplot function
Description
See autoplot for details.
Usage
autoplot(object,...)
Value
A ggplot object
See Also
Is conda installed?
Description
Only for internal usage.
Usage
is_exists_conda()
Value
Logical, TRUE if conda is installed.
Author(s)
Resul Akay
Probabilistic Time Series Forecasting
Description
Probabilistic time series forecasting via Natural Gradient Boosting for Probabilistic Prediction.
References
Duan, T et. al. (2019), NGBoost: Natural Gradient Boosting for Probabilistic Prediction.
Examples
## Not run:
library(ngboostForecast)
model <- NGBforecast$new(Dist = Dist("Normal"),
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 = 100,
tol = 1e-5)
model$fit(y = AirPassengers, seasonal = TRUE, max_lag = 12, xreg = NULL,
early_stopping_rounds = 10L)
fc <- model$forecast(h = 12, level = c(90, 80), xreg = NULL)
autoplot(fc)
## End(Not run)
Road Casualties in Great Britain 1969-84
Description
The Seatbelts dataset from the datasets package.
Usage
seatbelts
Format
An object of class mts (inherits from ts) with 192 rows and 8 columns.
Source
Harvey, A.C. (1989). Forecasting, Structural Time Series Models and the Kalman Filter. Cambridge University Press, pp. 519–523.
Durbin, J. and Koopman, S. J. (2001). Time Series Analysis by State Space Methods. Oxford University Press.
https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/UKDriverDeaths.html
References
Harvey, A. C. and Durbin, J. (1986). The effects of seat belt legislation on British road casualties: A case study in structural time series modelling. Journal of the Royal Statistical Society series A, 149, 187–227.
Scikit-Learn interface
Description
Scikit-Learn interface
Usage
sklearner(module = "tree", class = "DecisionTreeRegressor", ...)
Arguments
module |
scikit-learn module name, default is 'tree'. |
class |
scikit-learn's module class, default is 'DecisionTreeRegressor' |
... |
Other arguments passed to model class |
Author(s)
Resul Akay
Examples
## Not run:
sklearner(module = "tree", class = "DecisionTreeRegressor",
criterion="friedman_mse", min_samples_split=2)
## End(Not run)