In this code fragment:

```
cvresult = xgb.cv(xgb_param, xgtrain, num_boost_round=1000, nfold=cv_folds,
metrics='mlogloss', early_stopping_rounds=50)
```

`alg.set_params(n_estimators=cvresult.shape[0])`

How does this `cvresults.shape[0]`

returns the optimal number of estimators (`n_estimators`

).

I think `num_boost_round`

denote the value of `n_estimators`

used (increasing from 0 to 1000, early stopped by early_stopping_rounds), but I am not sure. What does `num_boost_round`

represent here, and more importantly, how to get the optimal number of estimators using `xgb.cv`

?