Compboost wraps the S4 class system exposed by Rcpp to make defining objects, adding objects, the training, calculating predictions, and plotting much easier. As already mentioned, the Compboost R6 class is just a wrapper and compatible with the most S4 classes.

R6Class object.

Usage

# Constructor
cboost = Compboost$new(data, target, optimizer = OptimizerCoordinateDescent$new(), loss,
learning_rate = 0.05, oob_fraction = NULL)
# Member functions
cboost$addLogger(logger, use_as_stopper = FALSE, logger_id, ...) cbboost$addBaselearner(feature, id, bl_factory, data_source = InMemoryData,
data_target = InMemoryData, ...)
cbboost$train(iteration = 100, trace = -1) cboost$getCurrentIteration()
cboost$prepareData(newdata) cboost$prepareResponse(response)
cboost$predict(newdata = NULL, as_response = FALSE) cboost$getInbagRisk()
cboost$getSelectedBaselearner() cboost$getEstimatedCoef()
cboost$plot(blearner_name = NULL, iters = NULL, from = NULL, to = NULL, length_out = 1000) cboost$getBaselearnerNames()
cboost$getLoggerData() cboost$calculateFeatureImportance(num_feats = NULL)
cboost$plotFeatureImportance(num_feats = NULL) cboost$plotInbagVsOobRisk()

Arguments

For Compboost$new(): data [data.frame] A data frame containing the data (features as well as target). target [character(1) or S4 Response] Character value containing the target variable or Response object. Note that the loss has to match the data type of the target. optimizer [S4 Optimizer] An initialized S4 Optimizer object exposed by Rcpp (e.g. OptimizerCoordinateDescent$new()) to specify how features are selected in each iteration.

loss

[S4 Loss]
Initialized S4 Loss object exposed by Rcpp which is used to calculate the risk and pseudo residuals (e.g. LossQuadratic$new()). learning_rage [numeric(1)] Learning rate to shrink the new parameters in each iteration. oob_fraction [numeric(1)] Fraction of how much data are used to calculate the out of bag risk. For cboost$addLogger():

logger

[S4 Logger]
Uninitialized S4 Logger class object that is registered in the model. See the details for possible choices.

use_as_stopper

[logical(1)]
Logical value indicating whether the new logger should also be used as stopper (early stopping). Default value is FALSE.

logger_id

[character(1)]
Id of the new logger. This is necessary to be able to register multiple logger.

...
Further arguments passed to the constructor of the S4 Logger class specified in logger. For possible arguments see details or the help pages (e.g. ?LoggerIteration).

For cboost$addBaselearner(): feature [character()] Vector of column names that are used as input data matrix for a single base-learner. Note that not every base-learner supports the use of multiple features (e.g. the spline base-learner does not). id [character(1)] Id of the base-learners. This is necessary since it is possible to define multiple learners using equal features. bl_factory [S4 Factory] Uninitialized base-learner factory given as S4 Factory class. See the details for possible choices. data_source [S4 Data] Data source object. Just in memory data objects are supported at the moment. data_target [S4 Data] Data target object. Just in memory data objects are supported at the moment. ... Further arguments passed to the constructor of the S4 Factory class specified in bl_factory. For possible arguments see the help pages (e.g. ?BaselearnerPSplineFactory) of the S4 classes. For cboost$train():

iteration

[integer(1)]
Number of iterations that are trained. If the model is already trained it sets to the given number by going back to already trained base-learners or it trains new ones. Note: This function defines an iteration logger with the id _iterations which is used as stopper for the new training.

trace

[integer(1)]
Integer indicating after how many iterations a trace should be printed. Specifying trace = 10, then every 10th iteration is printed. If you do not want to print the trace set trace = 0. Default is -1 which means that in total 40 iterations are printed.

For cboost$predict(): newdata [data.frame()] Data to predict on. If newdata equals NULL predictions on the training data are returned. For cboost$plot():

blearner_name

[character(1)]
Character name of the base-learner to plot the contribution to the response. Available choices for blearner_name use cboost$getBaselearnerNames(). iters [integer()] Integer vector containing the iterations the user wants to visualize. from [numeric(1)] Lower bound for the x axis (should be smaller than to). to [numeric(1)] Upper bound for the x axis (should be greater than from). length_out [integer(1)] Number of equidistant points between from and to used for plotting. For cboost$calculateFeatureImportance() and cboost$plotFeatureImportance(): num_feats [integer(1)] Number of features for which the Importance will be returned. Fields data [data.frame] Data used for training the algorithm. data_oob [data.frame] Data used for out of bag tracking. oob_fraction [numeric(1)] Fraction of how much data are used to track the out of bag risk. response [vector] Response object that is created or passed in target for training the model. response_oob [vector] Response object that is created by specifying the oob_fraction to evaluate each iteration. target [character(1)] Name of the target variable. id [character(1)] Name of the given dataset. optimizer [S4 Optimizer] Optimizer used within the fitting process. loss [S4 Loss] Loss used to calculate pseudo residuals and empirical risk. learning_rate [numeric(1)] Learning rate used to shrink the estimated parameter in each iteration. model [S4 Compboost_internal] S4 Compboost_internal class object from which the main operations (such as train) are called. bl_factory_list [S4 FactoryList] List of all registered factories represented as S4 FactoryList class. positive_category [character(1)] Character containing the name of the positive class in the case of (binary) classification. stop_if_all_stoppers_fulfilled [logical(1)] Logical indicating whether all stopper should be used simultaneously or if it is sufficient to just use the first stopper to stop the algorithm. Methods addLogger method to add a logger to the algorithm (Note: This is just possible before the training). addBaselearner method to add a new base-learner to the algorithm (Note: This is just possible before the training). getCurrentIteration method to get the current iteration on which the algorithm is set. train method to train the algorithm. predict method to predict on a trained object. getSelectedBaselearner method to get a character vector of selected base-learner. getEstimatedCoef method to get a list of estimated coefficient of each selected base-learner. plot method to plot individual feature effects. getBaselearnerNames method to get the names of the registered factories. prepareData method to prepare data to track the out of bag risk of an arbitrary loss/performance function. getLoggerData method to the the logged data from all registered logger. calculateFeatureImportance method to calculate feature importance. plotFeatureImportance method to plot the feature importance calculated by calulateFeatureImportance. plotInbagVsOobRisk method to plot the inbag vs the out of bag behavior. This is just applicable if a logger with name oob_logger was registered. This is automatically done if the oob_fraction is set. Examples cboost = Compboost$new(mtcars, "mpg", loss = LossQuadratic$new(), oob_fraction = 0.3) cboost$addBaselearner("hp", "spline", BaselearnerPSpline, degree = 3, n.knots = 10, penalty = 2, differences = 2)
#> Warning: Unused arguments "n.knots" in list.
cboost$train(1000) #> 1/1000 risk = 17 oob_risk = 16 #> 25/1000 risk = 3.4 oob_risk = 9.1 #> 50/1000 risk = 2.1 oob_risk = 8 #> 75/1000 risk = 1.9 oob_risk = 7.6 #> 100/1000 risk = 1.9 oob_risk = 7.5 #> 125/1000 risk = 1.8 oob_risk = 7.3 #> 150/1000 risk = 1.8 oob_risk = 7.2 #> 175/1000 risk = 1.8 oob_risk = 7.1 #> 200/1000 risk = 1.7 oob_risk = 7.1 #> 225/1000 risk = 1.7 oob_risk = 7 #> 250/1000 risk = 1.7 oob_risk = 6.9 #> 275/1000 risk = 1.7 oob_risk = 6.9 #> 300/1000 risk = 1.7 oob_risk = 6.8 #> 325/1000 risk = 1.7 oob_risk = 6.8 #> 350/1000 risk = 1.6 oob_risk = 6.8 #> 375/1000 risk = 1.6 oob_risk = 6.7 #> 400/1000 risk = 1.6 oob_risk = 6.7 #> 425/1000 risk = 1.6 oob_risk = 6.7 #> 450/1000 risk = 1.6 oob_risk = 6.7 #> 475/1000 risk = 1.6 oob_risk = 6.6 #> 500/1000 risk = 1.6 oob_risk = 6.6 #> 525/1000 risk = 1.6 oob_risk = 6.6 #> 550/1000 risk = 1.6 oob_risk = 6.6 #> 575/1000 risk = 1.6 oob_risk = 6.6 #> 600/1000 risk = 1.6 oob_risk = 6.6 #> 625/1000 risk = 1.5 oob_risk = 6.6 #> 650/1000 risk = 1.5 oob_risk = 6.6 #> 675/1000 risk = 1.5 oob_risk = 6.5 #> 700/1000 risk = 1.5 oob_risk = 6.5 #> 725/1000 risk = 1.5 oob_risk = 6.5 #> 750/1000 risk = 1.5 oob_risk = 6.5 #> 775/1000 risk = 1.5 oob_risk = 6.5 #> 800/1000 risk = 1.5 oob_risk = 6.5 #> 825/1000 risk = 1.5 oob_risk = 6.5 #> 850/1000 risk = 1.5 oob_risk = 6.5 #> 875/1000 risk = 1.5 oob_risk = 6.5 #> 900/1000 risk = 1.5 oob_risk = 6.5 #> 925/1000 risk = 1.5 oob_risk = 6.5 #> 950/1000 risk = 1.5 oob_risk = 6.5 #> 975/1000 risk = 1.5 oob_risk = 6.5 #> 1000/1000 risk = 1.5 oob_risk = 6.5 #> #> #> Train 1000 iterations in 0 Seconds. #> Final risk based on the train set: 1.5 #> table(cboost$getSelectedBaselearner())
#> #> hp_spline #> 1000
cboost$plot("hp_spline") cboost$plotInbagVsOobRisk()
{"ft_lang_label":"__label__en","ft_lang_prob":0.6656659,"math_prob":0.9656186,"size":9389,"snap":"2019-43-2019-47","text_gpt3_token_len":2817,"char_repetition_ratio":0.18391049,"word_repetition_ratio":0.117154814,"special_character_ratio":0.30013847,"punctuation_ratio":0.13890524,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9901635,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,3,null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-10-22T09:38:23Z\",\"WARC-Record-ID\":\"<urn:uuid:edf82ad7-bea7-49df-8560-90ac24a104e6>\",\"Content-Length\":\"25633\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:24317600-dd77-463e-9e33-bd068924598a>\",\"WARC-Concurrent-To\":\"<urn:uuid:3e24e9c3-a237-43cc-85ad-4cad0b43b67c>\",\"WARC-IP-Address\":\"185.199.110.153\",\"WARC-Target-URI\":\"https://danielschalk.com/compboost/reference/Compboost.html\",\"WARC-Payload-Digest\":\"sha1:4EFPCEG53YR457QHKSMP7R5EXBPIYLMP\",\"WARC-Block-Digest\":\"sha1:SEC364KZSSPZTBG3JSYJRX576KJ2QVKS\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-43/CC-MAIN-2019-43_segments_1570987813307.73_warc_CC-MAIN-20191022081307-20191022104807-00473.warc.gz\"}"}