小编Tad*_*. A的帖子

python - 尝试使用 Keras 进行预测时返回 nan

对于一个学校项目,我尝试使用 keras 框架预测数据,但当我尝试获取预测数据时,它返回“nan”损失和值。

源代码 :

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=5)

# create model
model = Sequential()
model.add(Dense(950, input_shape=(425,), activation='relu'))
model.add(Dense(425, activation='relu'))
model.add(Dense(200, activation='relu'))
model.add(Dense(50, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

# Compile model
sgd = optimizers.SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='mean_squared_error', optimizer='sgd')

# Fit the model
model.fit(X_train, y_train, epochs=20, batch_size=1, verbose=1)

#evaluate the model
y_pred = model.predict(X_test)

score = model.evaluate(X_test, y_test,verbose=1)
print(score)

# calculate predictions
predictions = model.predict(X_pred)
Run Code Online (Sandbox Code Playgroud)

数据 :

X_train 和 X_test 是 5000 行(样本数)* 425 列(维度数)的(panda)数据帧。

y_train 和 …

python machine-learning keras

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

keras ×1

machine-learning ×1

python ×1