# xgb.cv

0th

Percentile

##### Cross Validation

The cross valudation function of xgboost

##### Usage
xgb.cv(params = list(), data, nrounds, nfold, label = NULL,
missing = NULL, prediction = FALSE, showsd = TRUE, metrics = list(),
obj = NULL, feval = NULL, stratified = TRUE, folds = NULL,
verbose = T, print.every.n = 1L, early.stop.round = NULL,
maximize = NULL, ...)
##### Arguments
params
the list of parameters. Commonly used ones are:
• objectiveobjective function, common ones are
• reg:linearlinear regression
• binary:logisticlogistic regression for classification
data
takes an xgb.DMatrix or Matrix as the input.
nrounds
the max number of iterations
nfold
the original dataset is randomly partitioned into nfold equal size subsamples.
label
option field, when data is Matrix
missing
Missing is only used when input is dense matrix, pick a float value that represents missing value. Sometime a data use 0 or other extreme value to represents missing values.
prediction
A logical value indicating whether to return the prediction vector.
showsd
boolean, whether show standard deviation of cross validation
metrics,
list of evaluation metrics to be used in corss validation, when it is not specified, the evaluation metric is chosen according to objective function. Possible options are:
• errorbinary classification error rate
• rmse
 obj customized objective function. Returns gradient and second order gradient with given prediction and dtrain. feval custimized evaluation function. Returns list(metric='metric-name', value='metric-value') with given prediction and dtrain. stratified boolean whether sampling of folds should be stratified by the values of labels in data folds list provides a possibility of using a list of pre-defined CV folds (each element must be a vector of fold's indices). If folds are supplied, the nfold and stratified parameters would be ignored. verbose boolean, print the statistics during the process print.every.n Print every N progress messages when verbose>0. Default is 1 which means all messages are printed. early.stop.round If NULL, the early stopping function is not triggered. If set to an integer k, training with a validation set will stop if the performance keeps getting worse consecutively for k rounds. maximize If feval and early.stop.round are set, then maximize must be set as well. maximize=TRUE means the larger the evaluation score the better. ... other parameters to pass to params. 
 
 Details The original sample is randomly partitioned into nfold equal size subsamples.Of the nfold subsamples, a single subsample is retained as the validation data for testing the model, and the remaining nfold - 1 subsamples are used as training data.The cross-validation process is then repeated nrounds times, with each of the nfold subsamples used exactly once as the validation data.All observations are used for both training and validation.Adapted from http://en.wikipedia.org/wiki/Cross-validation_%28statistics%29#k-fold_cross-validation Value If prediction = TRUE, a list with the following elements is returned: dtadata.tablewith each mean and standard deviation stat for training set and test setpredan array or matrix (for multiclass classification) with predictions for each CV-fold for the model having been trained on the data in all other folds.If prediction = FALSE, just a data.table with each mean and standard deviation stat for training set and test set is returned. Aliases xgb.cv Examples data(agaricus.train, package='xgboost') dtrain <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label) history <- xgb.cv(data = dtrain, nround=3, nthread = 2, nfold = 5, metrics=list("rmse","auc"), max.depth =3, eta = 1, objective = "binary:logistic") print(history) Documentation reproduced from package xgboost, version 0.4-2, License: Apache License (== 2.0) | file LICENSE Community examples Looks like there are no examples yet. Post a new example: 
 
 
 R package Rdocumentation.org Created by DataCamp.com 
 Put your R skills to the test window.MathJax = { tex: { inlineMath: [ ['$','$'], ['\$$','\$$'] ], displayMath: [ ['$$','$$'] ], processEscapes: true, packages: ['base', 'ams', 'noerrors', 'noundefined'] }, options: { ignoreHtmlClass: 'tex2jax_ignore', processHtmlClass: 'tex2jax_process' }, loader: { load: ['[tex]/noerrors'] } }; var $jq = jQuery.noConflict(); ;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[]; p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments) };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1; n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","//cdn.datacamp.com/sp/2.10.2.js","snowplow")); var options = { appId: 'rdocumentation', platform: 'web', post: true, discoverRootDomain: true, contexts: { webPage: true, performanceTiming: true } }; options.forceSecureTracker = true; options.postPath = '/spevent'; window.snowplow('newTracker', 'co', "www.datacamp.com", options); window.snowplow('enableActivityTracking', 10, 10); // Ping every 10 seconds after 10 seconds window.snowplow('enableLinkClickTracking'); window.snowplow('trackPageView', null, [ { schema: 'iglu:com.datacamp/user/jsonschema/1-0-0', data: { anonId:$jq.cookie('dc_aid'), } } ]); var config = { forms: { whitelist: ["snowplow_tracked"] }, fields: { blacklist: ['password', 'password_confirmation'] } }; window.snowplow('enableFormTracking', config); (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-41577880-1', 'rdocumentation.org'); ga('send', 'pageview');