如何解决ValueError:输入包含NaN,无穷大或对于dtype('float64')而言太大的值 [英] How to resolve ValueError: Input contains NaN, infinity or a value too large for dtype('float64')
本文介绍了如何解决ValueError:输入包含NaN,无穷大或对于dtype('float64')而言太大的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有这个代码:
####----Data----####
quest=pd.read_csv("inputFile.csv", names=["A1","A2",..."A200","Sim"])
print(quest.head())
####----Set up Data and Label----####
X=quest.drop('Sim',axis=1)
y=quest['Sim']
####----Train Test Split----####
X_train, X_test, y_train, y_test = train_test_split(X, y)
np.isfinite(X_train).any(), np.isfinite(y_train).any(),np.isfinite(X_test).any()
np.isnan(X_train).any(), np.isnan(y_train).any(), np.isnan(X_test).any()
####----Data Pre-Processing----####
scaler=StandardScaler()
# Fit only to the training data
X_scaled=scaler.fit(X_train)
# Now apply the transformations to the data:
X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)
####----Training the Model----####
mlp=MLPClassifier(hidden_layer_sizes=(13,13,13), max_iter=500)
mlp.fit(X_train,y_train)
print(mlp)
####----Predictions and Evaluation----####
predictions=mlp.predict(X_test)
print(confusion_matrix(y_test,predictions))
print(classification_report(y_test,predictions))
但是我得到了这个错误:
but I got this error:
回溯(最近通话最近):
Traceback (most recent call last): File "E:\thesis\sk-ANN.py", line 67, in
X_scaled=scaler.fit(X_train)...
ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
我的数据集具有指数形式的值,如下所示:
My data set has values in exponential form, like this:
2.15E-06 -0.000556462 0.000197385 -0.000919 -0.000578077....
mlp.fit(X_train,y_train) 和 predictions = mlp.predict(X_test) 有人请帮我如何解决这个问题
the same error occur at mlp.fit(X_train,y_train) and predictions=mlp.predict(X_test) Someone please help me how to resolve this problem
推荐答案
我猜输入数据中必须有nan
值,因此在缩放值之前,请将所有nan设置为avg.列或设置为零,请参考此.
I guess there must be nan
values in input data, so before scaling values set all nan to avg. of column or set to zero, refer this.
这篇关于如何解决ValueError:输入包含NaN,无穷大或对于dtype('float64')而言太大的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文