# how does xgboost handle inf or -inf values?

I am using xgboost for binary classfication. I have infs and -infs in my data due to the fact I am calculating ratios from one col and and another e.g. df[col1]/df[col2]. Since I have zeros and nans in these columns, it leads to me gettings infs, -infs, and nans.

I know xgboost can handle nan values, but if I replace the infs with a very large number e.g. 99999 or -99999 for -inf, is this an issue for xgboost? my understanding is that tree based methods for classification are unaffected by 'outliers'/inf values.

What would be best method to handle these?

Since (most) tree-based methods only care about the ordering of values in each feature, replacing your infinite values with very large values (larger than any finite value of the feature) is fine. Of course, you'll have to do some thinking of whether df[col1]/df[col2] should actually be treated as $$\pm$$inf when col2 is zero, and nans can just be left in for xgboost.