ValueError: Input contains NaN, infinity or a value too large for dtype('float32')

Hello

I try to run XGBoost Regressor with Sklearn: But when I run the code : I have this error :
ValueError: Input contains NaN, infinity or a value too large for dtype(‘float32’).

Thanks

As the error message suggests, check your input data.

Thanks for answer but in my data I don’t have Nan Value, I try some method to filting nan but also does’n worked .

I don’t know if you have some solutions because I want ao apply XGBoost regressor and cross validation

The error may be coming from scikit-learn, not XGBoost. See https://datascience.stackexchange.com/questions/11928/valueerror-input-contains-nan-infinity-or-a-value-too-large-for-dtypefloat32

Please, replace NaN Values with mean

df.fillna(df.mean(), inplace=True)

df is your data. if there are large outliers in your data, use

#Replace NaN Values with median
df1.fillna(df.median(), inplace=True)

Note, also for XGBoost ML, this error usually comes up during the cross-validation (splitting of data) phase but you have to go back and to the import data line and add do the panda replacement.

I got the same error message when using sklearn with pandas . My solution is to reset the index of my dataframe df before running any sklearn code:

df = df.reset_index()