Xgboost crossvalidated model access
<p>Is there any way I can access the trained <code>xgboost</code> model from <code>xgboost.cv</code> directly? Or do I manually have to loop over the folds and perform a fit in this case?</p>

<pre><code>xgb.cv(param, dtrain, num_round, nfold = 5, seed = 0,
       obj = logregobj, feval=evalerror)
</code></pre>

<p>First, you cross-validate xgboost as you indicate:</p>

<p><code>xgb.cv_m &lt;- xgb.cv(param, dtrain, num_round, nfold = 5, seed = 0, obj = logregobj, feval=evalerror)</code></p>

<p>Then, the number of rounds needed corresponds to the best AUC (the AUC train and test means and std resulted from cross-validation are saved in the data frame 'dt' - check out <code>names(xgb_cv_m)</code>):</p>

<p><code>nr &lt;- which(xgb_cv_m$dt$test.auc.mean == max(xgb_cv_m$dt$test.auc.mean))</code></p>

<p>Next, when you fit the final model using 'xgboost' you use nrounds=nr</p>

<p>If you wish, you can also visually inspect the performance at every round by: <code>plot(xgb_cv_m$dt$test.auc.mean)</code></p>

python data-science xgboost