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, 2019 in Machine Learning by Amulya
6,094 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, 2019 by Maya

Related Questions In Machine Learning

0 votes
1 answer
+1 vote
1 answer
0 votes
2 answers
0 votes
2 answers

What is supervised learning?

Supervised learning is the machine learning task ...READ MORE

answered Sep 3, 2019 in Data Analytics by anonymous
• 32,930 points
175 views
0 votes
1 answer

What is semi-supervised machine learning?

Hi@Ganesh, Semi-supervised machine learning is a combination of ...READ MORE

answered Jul 18, 2020 in Machine Learning by MD
• 95,140 points
226 views
0 votes
1 answer

What is Reinforcement learning?

Alright, let me not get into the ...READ MORE

answered May 8, 2019 in Machine Learning by Alok
359 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, 2019 in Machine Learning by Fatima
276 views