ValueError: Input contains NaN, infinity or a value too large for dtype('float32')

0 votes

I got ValueError when predicting test data using a RandomForest model.

clf = RandomForestClassifier(n_estimators=10, max_depth=6, n_jobs=1, verbose=2)
clf.fit(X_fit, y_fit)

df_test.fillna(df_test.mean())
X_test = df_test.values  
y_pred = clf.predict(X_test)

error:

ValueError: Input contains NaN, infinity or a value too large for dtype('float32').
May 23 in Machine Learning by Amulya
162 views

1 answer to this question.

0 votes

Assuming X_test is a pandas dataframe, you can use DataFrame.fillna to replace the NaN values with the mean:

X_test.fillna(X_test.mean())
answered May 23 by Maya

Related Questions In Machine Learning

0 votes
1 answer
0 votes
1 answer

Can an ML model be recreated or retrained?

Of course, your model is retrainable, in ...READ MORE

answered May 13 in Machine Learning by Hemant
20 views
0 votes
1 answer

What is supervised learning?

Supervised learning is an aspect of machine learning ...READ MORE

answered May 8 in Data Analytics by Alok
22 views
0 votes
0 answers

What is semi-supervised machine learning?

What is semi-supervised machine learning? READ MORE

May 8 in Machine Learning by Ganesh
12 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How do I create a decision tree?

Let us consider the following example. Suppose a ...READ MORE

answered May 13 in Machine Learning by Fatima
24 views