Scikit Learn - ValueError: Array contains NaN or infinity

匿名 (未验证) 提交于 2019-12-03 02:27:02

问题:

There are no NaNs in my dataset, I have checked thoroughly. Any reason why I keep getting this error when trying to fit my classifier? Some of the numbers in the data set are rather large and some decimal places go out 10 decimal points but I wouldn't thing that should cause an error. I included some of my pandas DataFrame info 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. 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!