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
743 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
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, 2019 in Machine Learning by Hemant
45 views
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,440 points
60 views
0 votes
0 answers

What is semi-supervised machine learning?

What is semi-supervised machine learning? READ MORE

May 8, 2019 in Machine Learning by Ganesh
46 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
39 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
92 views