from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier(estimators = 6, criterion = 'entropy', random_state = 0)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
Asked
Active
Viewed 128 times
-1

tlentali
- 3,407
- 2
- 14
- 21

KHAN ABDUL RAHMAN
- 11
- 1
-
Please can you show us the error and give us a little more context about your code – Xander Bielby Sep 07 '21 at 09:53
1 Answers
0
This is my function (based on this) to clean the dataset of nan, Inf, and missing cells. So make sure that you have non NaN values in your input. And all those values are actually float values. None of the values should be Inf either.
This error occurs when the following function is called : Github
def _assert_all_finite(X):
"""Like assert_all_finite, but only for ndarray."""
X = np.asanyarray(X)
# First try an O(n) time, O(1) space solution for the common case that
# everything is finite; fall back to O(n) space np.isfinite to prevent
# false positives from overflow in sum method.
if (X.dtype.char in np.typecodes['AllFloat'] and not np.isfinite(X.sum())
and not np.isfinite(X).all()):
raise ValueError("Input contains NaN, infinity"
" or a value too large for %r." % X.dtype)

Salio
- 1,058
- 10
- 21