简体   繁体   中英

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

I am not familiar with python and am trying to run a decision tree classifier in python using SKLEARN library and when I run the code, I encounters the error:

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

I have tried using a smaller subset of my excel datasheet and the code is able to execute with the results I want. So I suspect the problem is that my data set is too big. Here is my code that causes the crash:

df_X = data_train[['DayOfWeek', 'Promo', 'StateHoliday']]
df_Y = data_train[['Sales_band']]

X_train, X_test, y_train, y_test = train_test_split(df_X, df_Y, random_state=1)
model = tree.DecisionTreeClassifier()
model.fit(X_train, y_train) // Line that causes crash
y_predict = model.predict(X_test)

print('The accuracy of the Decision Tree is', accuracy_score(y_test, y_predict))

You may have missing values in your dataset. You may want to use dropna() to remove all rows containing missing values if it won't affect the quality of your prediction/accuracy of prediction

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM