NGBClassifier | R Documentation |
NGBRegressor is a wrapper for the generic NGBoost class that facilitates classifier.Use this class if you want to predict an outcome that could take an infinite number of (ordered) values.
new()
Initialize NGBoost Classifier model.
NGBClassifier$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 )
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
An NGBRegressor object that can be fit.
fit()
An NGBRegressor object that can be fit.
NGBClassifier$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 )
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.
NULL
feature_importances()
Return the feature importances for all parameters in the distribution (the higher, the more important the feature).
NGBClassifier$feature_importances()
A data frame
plot_feature_importance()
Plot feature importance
NGBClassifier$plot_feature_importance()
predict()
Point prediction of Y at the points X=x
NGBClassifier$predict(X, max_iter = NULL)
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
Numpy array of the estimates of Y
predict_proba()
Probability prediction of Y at the points X=x
NGBClassifier$predict_proba(X, max_iter = NULL)
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
Numpy array of the estimates of Y
predict_pred_dist()
Predict the conditional distribution of Y at the points X=x
NGBClassifier$predict_pred_dist(X, max_iter = NULL)
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
Numpy array of the estimates of Y
staged_pred_dist()
Predict the conditional distribution of Y at the points X=x at multiple boosting iterations
NGBClassifier$staged_pred_dist(X, max_iter = NULL)
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
A list of NGBoost distribution objects, one per boosting stage up to max_iter.
staged_pred()
Point prediction of Y at the points X=x at multiple boosting iterations.
NGBClassifier$staged_pred(X, max_iter = NULL)
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
A list of NGBoost distribution objects, one per boosting stage up to max_iter.
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.
NGBClassifier$set_params(...)
...
dict (a named R list). Estimator parameters.
self : estimator instance. Estimator instance.
get_params()
Get parameters for this estimator.
NGBClassifier$get_params(deep = TRUE)
deep
bool, default = TRUE If True, will return the parameters for this estimator and contained subobjects that are estimators.
params. A dict (R list). Parameter names mapped to their values.
pred_dist()
Predict the conditional distribution of Y at the points X=x
NGBClassifier$pred_dist(X, max_iter = NULL)
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.
See for available methods NGBDistClass
A NGBDistClass Class
clone()
The objects of this class are cloneable with this method.
NGBClassifier$clone(deep = FALSE)
deep
Whether to make a deep clone.
Resul Akay
## Not run: data(BreastCancer, package = "mlbench") dta <- na.omit(BreastCancer) dta <- rsample::initial_split(dta) train <- rsample::training(dta) test <- rsample::testing(dta) x_train = train[,2:10] y_train = as.integer(train[,11]) x_test = test[,2:10] y_test = as.integer(test[,11]) model <- NGBClassifier$new(Dist = Dist("k_categorical", K = 3), Base=DecisionTreeRegressor( criterion='friedman_mse', max_depth=2), Score = Scores("LogScore"), natural_gradient=TRUE, n_estimators=500, learning_rate=0.01, minibatch_frac=1.0, col_sample=0.2, verbose=TRUE, verbose_eval=1, tol=1e-5, random_state = NULL) model$fit(x_train, y_train, X_val = x_test, Y_val = y_test) model$feature_importances() model$plot_feature_importance() model$predict(x_test) model$predict_proba(x_test) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.