1
所以我有這個代碼的值:如何解決ValueError異常:輸入包含的NaN,無窮大或過大的D型(「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))
,但我得到這個錯誤:
回溯(過去最近一次調用): 文件 「E:\論文\ sk-ANN.py」 67行,在
X_scaled=scaler.fit(X_train)...
ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
我的數據集在指數形式值,如:
2.15E-06 -0.000556462 0.000197385 -0.000919 -0.000578077....
同樣的錯誤發生在mlp.fit(X_train,y_train)和預測= mlp.predict(X_test) 有人請幫助我如何解決這個問題
我工作過..謝謝 –