Response variable should be larger or equal to 0 but some prediction values smaller than 0

I use R package “xgboost” to train the model. And my response variable are species richness, and I used the trained model to predict. But there are some negative values in prediction. But actually richness should be >= 0. So is any suggestion to solve this?

Try log-transforming the label (response) so that it ranges from -inf to inf. Then at prediction time, you can take the exponential function.