3

我的数据集中没有 NaN,我已经彻底检查过了。为什么我在尝试适合我的分类器时不断收到此错误?数据集中的一些数字相当大,一些小数位会保留 10 个小数点,但我不会认为这会导致错误。我在下面包含了一些我的 pandas DataFrame 信息以及错误本身。有任何想法吗?

<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.
4

0 回答 0