NGBRegression: Constructor for NGBoost regression models.

NGBRegressionR Documentation

Constructor for NGBoost regression models.

Description

NGBRegressor is a wrapper for the generic NGBoost class that facilitates regression.Use this class if you want to predict an outcome that could take an infinite number of (ordered) values.

Methods

Public methods


Method new()

Initialize NGBoost regression model.

Usage
NGBRegression$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.

Score

Rule to compare probabilistic predictions to the observed data. A score from ngboost.scores, e.g. LogScore

Base

Base learner to use in the boosting algorithm. Any instantiated sklearn regressor, e.g. 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

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.

A

Distribution from ngboost.distns, e.g. Normal

Returns

An NGBRegressor object that can be fit.


Method fit()

An NGBRegressor object that can be fit.

Usage
NGBRegression$fit(
  X,
  Y,
  X_val = NULL,
  Y_val = NULL,
  sample_weight = NULL,
  val_sample_weight = NULL,
  train_loss_monitor = NULL,
  val_loss_monitor = NULL,
  early_stopping_rounds = NULL
)
Arguments
X

DataFrame object or List or numpy array of predictors (n x p) in Numeric format

Y

DataFrame object or List or numpy array of outcomes (n) in numeric format. Should be floats for regression and integers from 0 to K-1 for K-class classification

X_val

DataFrame object or List or numpy array of validation-set predictors in numeric format

Y_val

DataFrame object or List or numpy array of validation-set outcomes in numeric format

sample_weight

how much to weigh each example in the training set. numpy array of size (n) (defaults to 1)

val_sample_weight

How much to weigh each example in the validation set. (defaults to 1)

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.

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

early_stopping_rounds

The number of consecutive boosting iterations during which the loss has to increase before the algorithm stops early.

Returns

NULL


Method feature_importances()

Return the feature importances for all parameters in the distribution (the higher, the more important the feature).

Usage
NGBRegression$feature_importances()
Returns

A data frame


Method plot_feature_importance()

Plot feature importance

Usage
NGBRegression$plot_feature_importance()

Method predict()

Point prediction of Y at the points X=x

Usage
NGBRegression$predict(X, max_iter = NULL)
Arguments
X

DataFrame object or List or numpy array of predictors (n x p) in numeric Format

max_iter

Get the prediction at the specified number of boosting iterations

Returns

Numpy array of the estimates of Y


Method staged_pred_dist()

Predict the conditional distribution of Y at the points X=x at multiple boosting iterations

Usage
NGBRegression$staged_pred_dist(X, max_iter = NULL)
Arguments
X

DataFrame object or List or numpy array of predictors (n x p) in numeric Format

max_iter

Get the prediction at the specified number of boosting iterations

Returns

A list of NGBoost distribution objects, one per boosting stage up to max_iter.


Method staged_pred()

Point prediction of Y at the points X=x at multiple boosting iterations.

Usage
NGBRegression$staged_pred(X, max_iter = NULL)
Arguments
X

DataFrame object or List or numpy array of predictors (n x p) in numeric Format

max_iter

Get the prediction at the specified number of boosting iterations

Returns

A list of NGBoost distribution objects, one per boosting stage up to max_iter.


Method set_params()

Set the parameters of this estimator. The method works on simple estimators as well as on nested objects (such as :class:~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it's possible to update each component of a nested object.

Usage
NGBRegression$set_params(...)
Arguments
...

dict (a named R list). Estimator parameters.

Returns

self : estimator instance. Estimator instance.


Method get_params()

Get parameters for this estimator.

Usage
NGBRegression$get_params(deep = TRUE)
Arguments
deep

bool, default = TRUE If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params. A dict (R list). Parameter names mapped to their values.


Method pred_dist()

Predict the conditional distribution of Y at the points X=x

Usage
NGBRegression$pred_dist(X, max_iter = NULL)
Arguments
X

DataFrame object or List or numpy array of predictors (n x p) in numeric format.

max_iter

get the prediction at the specified number of boosting iterations.

Details

See for available methods NGBDistReg

Returns

A NGBDistReg Class


Method clone()

The objects of this class are cloneable with this method.

Usage
NGBRegression$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Author(s)

Resul Akay

Examples

## Not run: 

data(Boston, package = "MASS")

dta <- rsample::initial_split(Boston)

train <- rsample::training(dta)

test <- rsample::testing(dta)


x_train = train[,1:13]
y_train = train[,14]

x_test = test[,1:13]
y_test = test[,14]


model <- NGBRegression$new(Dist = Dist("Exponential"),
                           Base=DecisionTreeRegressor(
                             criterion="mae",
                             min_samples_split=2,
                             min_samples_leaf=1,
                             min_weight_fraction_leaf=0.0,
                             max_depth=5,
                             splitter="best",
                             random_state=NULL),
                           Score = Scores("MLE"),
                           natural_gradient=TRUE,
                           n_estimators= 600,
                           learning_rate= 0.002,
                           minibatch_frac= 0.8,
                           col_sample= 0.9,
                           verbose=TRUE,
                           verbose_eval=100,
                           tol=1e-5)

model$fit(X = x_train, Y = y_train, X_val = x_test, Y_val = y_test)

model$feature_importances()

model$plot_feature_importance()

model$predict(x_test)


## End(Not run)



Akai01/ngboost documentation built on Nov. 21, 2022, 10:05 a.m.