【问题标题】:Python Tensorflow "X" values are endlessPython Tensorflow“X”值无穷无尽
【发布时间】:2021-10-20 09:31:09
【问题描述】:

我的 Python 代码和我的数据库有问题。我的 Python 代码如下:

from tensorflow.keras.layers import Dense
from tensorflow.keras.optimizers import SGD
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.preprocessing import StandardScaler
import pandas as pd
import tensorflow as tf
from tensorflow.keras.models import Sequential, load_model
from tensorflow.keras.layers import Dense
from sklearn.metrics import accuracy_score
import numpy as np

dataset = pd.read_csv('dataset.csv')
x = dataset.drop(columns=['good/bad']).values
y = dataset['good/bad'].values

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3)

scaler = StandardScaler().fit(x_train)
x_train = scaler.transform(x_train)
x_test = scaler.transform(x_test)

# fit the model
model = Sequential()
model.add(Dense(units=32, activation='relu', input_dim=(x_train.shape[1])))
model.add(Dense(units=64, activation='relu'))
model.add(Dense(units=1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer=SGD(learning_rate=0.01), metrics=['accuracy'])
model.fit(x_train, y_train, epochs=10, batch_size=32, verbose=1)
y_hat = model.predict(x_test)
print(y_hat)
y_hat2 = [0 if val < 0.5 else 1 for val in y_hat]
print(accuracy_score(y_test, np.where(y_hat > 0.5, 1, 0)))

model.save("/home/pi/Anti-DDoS/model_out3.h5")

dataset.csv(我必须显示一个下载链接,因为它只适用于整个文件)

https://www.file-upload.net/download-14723867/database_final_mix.csv.html

当我尝试打印 x 时,会出现以下输出:

[[4.0000e+00 5.0000e+00 0.0000e+00 ... 4.0960e+03 2.7869e+04 0.0000e+00]
 [4.0000e+00 5.0000e+00 0.0000e+00 ... 2.5400e+02 3.9591e+04 0.0000e+00]
 [4.0000e+00 5.0000e+00 0.0000e+00 ... 5.0100e+02 6.5240e+03 0.0000e+00]
 ...
 [4.0000e+00 5.0000e+00 0.0000e+00 ... 5.0100e+02 5.1124e+04 0.0000e+00]
 [4.0000e+00 5.0000e+00 0.0000e+00 ... 9.6740e+03 7.2280e+03 0.0000e+00]
 [4.0000e+00 5.0000e+00 0.0000e+00 ... 2.5400e+02 4.0740e+03 0.0000e+00]]

...当我尝试拟合模型时,损失为 Nan

Epoch 1/10



32/14130 [..............................] - ETA: 2:52 - loss: 0.6792 - acc: 0  480/14130 [>.............................] - ETA: 12s - loss: 0.6954 - acc: 0.  992/14130 [=>............................] - ETA: 6s - loss: 0.6984 - acc: 0.4 1536/14130 [==>...........................] - ETA: 4s - loss: 0.6925 - acc: 0.5 2080/14130 [===>..........................] - ETA: 3s - loss: 0.6882 - acc: 0.5 2592/14130 [====>.........................] - ETA: 2s - loss: 0.6836 - acc: 0.5 3136/14130 [=====>........................] - ETA: 2s - loss: nan - acc: 0.537914130/14130 [==============================] - 2s 126us/sample - loss: nan - acc: 0.4494

我不知道如何解决这个问题。请帮帮我。

【问题讨论】:

    标签: python tensorflow keras


    【解决方案1】:

    错误是在我的数据库中是一个不存在的值,,。因此,X 不定式的值和代码不起作用。

    【讨论】:

      猜你喜欢
      • 2014-10-09
      • 2013-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-12
      • 1970-01-01
      相关资源
      最近更新 更多