gpt4 book ai didi

python - 神经网络数据标准化引发 ValueError : Input contains NaN, 无穷大或值对于 float64 来说太大

转载 作者:行者123 更新时间:2023-12-02 09:59:42 25 4
gpt4 key购买 nike

我的数据集具有指数形式的值,如下所示:

2.15E-06    -0.000556462    0.000197385 -0.000919   -0.000578077....

这是代码:

    ####----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:\thesis\sk-ANN.py”,第 67 行,位于

X_scaled=scaler.fit(X_train)...
ValueError: Input contains NaN, infinity or a value too large for dtype('float64').

拟合和预测模型“mlp.fit(X_train,y_train”和“predictions=mlp.predict(X_test)”时会出现相同的错误

如何消除此错误?

最佳答案

我认为你需要预处理你的数据集。您可以将 Nan 值替换为一些有意义的值。一些有用的答案可以在这里看到 - numpy array: replace nan values with average of columns

关于python - 神经网络数据标准化引发 ValueError : Input contains NaN, 无穷大或值对于 float64 来说太大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46805647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com