AttributeError: 'numpy.ndarray' object has no attribute 'nan_to_num' I'm trying to run a Random Forest model from sklearn but I keep getting an error: ValueError: Input contains NaN, infinity or a value too large for dtype('float32').
I tried following steps in ValueError: Input contains NaN, infinity or a value too large for dtype(&#39;float32&#39;)
fillna(0) on my pandas dataframe still gave the ValueError.
So I tried working with my numpy array:
val = setTo.ravel().nan_to_num(0)

But I keep getting an error: 'numpy.ndarray' object has no attribute 'nan_to_num'
I'm wondering how I can deal with the nan values if I have ndarray?
Thanks so much!
Update
Thanks so much to @Beniamin H for all the help, as per suggested, I rescalled the data, which I based on https://stackoverflow.com/questions/34771118/sklearn-random-forest-error-on-input and it worked!
You are using the right method but in a wrong way :)
nan_to_num is a method of numpy module, not numpy.ndarray. So instead of calling nan_to_num on you data, call it on numpy module giving your data as a paramter:
import numpy as np
data = np.array([1,2,3,np.nan,np.nan,5])
data_without_nan = np.nan_to_num(data)

prints:
array([1., 2., 3., 0., 0., 5.])

In your example:
import numpy as np
val = np.nan_to_num(setTo.ravel())