Scikit Learn - ValueError: array contains NaN or infinity

There is no NaN in my dataset, I checked it carefully. Any reason I get this error when trying to pick up my classifier? Some of the numbers in the data set are quite large, and some decimal places come out of ten decimal places, but I would not cause the error. I have included some of my pandas DataFrame data below, as well as the error itself. Any ideas?

<class 'pandas.core.frame.DataFrame'> DatetimeIndex: 6244 entries, 1985-02-06 00:00:00 to 2009-11-05 00:00:00 Data columns (total 86 columns): dtypes: float64(86) clf = RandomForestClassifier(n_estimators=100,min_samples_split=4) clf.fit(train, train_target) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-150-fa4acb362bc6> in <module>() 1 clf = RandomForestClassifier(n_estimators=100,min_samples_split=4) ----> 2 clf.fit(train, train_target) 3 clf.score(test, test_target) C:\Anaconda\lib\site-packages\sklearn\ensemble\forest.pyc in fit(self, X, y, sample_weight) 255 # Convert data 256 X, = check_arrays(X, dtype=DTYPE, sparse_format="dense", --> 257 check_ccontiguous=True) 258 259 # Remap output C:\Anaconda\lib\site-packages\sklearn\utils\validation.pyc in check_arrays(*arrays, **options) 231 else: 232 array = np.asarray(array, dtype=dtype) --> 233 _assert_all_finite(array) 234 235 if copy and array is array_orig: C:\Anaconda\lib\site-packages\sklearn\utils\validation.pyc in _assert_all_finite(X) 25 if (X.dtype.char in np.typecodes['AllFloat'] and not np.isfinite(X.sum()) 26 and not np.isfinite(X).all()): ---> 27 raise ValueError("Array contains NaN or infinity.") 28 29 ValueError: Array contains NaN or infinity. 
+3
source share

Source: https://habr.com/ru/post/1200103/


All Articles