python - Kaggle 泰坦尼克号与 tflearn 神经网络

标签 python tensorflow machine-learning deep-learning kaggle

我已经用逻辑回归解决了泰坦尼克号问题,现在我想用神经网络解决问题。但我的模型总是返回1,这意味着幸存。对于每个测试输入。也许我的模型有问题。我该如何解决这个问题?

train_data = pd.read_csv('data/train.csv')
test_data = pd.read_csv('data/test.csv')

#Some data cleaning process
#......


X_train = train_data.drop("Survived",axis=1).as_matrix()
Y_train = train_data["Survived"].as_matrix().reshape((891,1))
X_test  = test_data.drop("PassengerId",axis=1).as_matrix()


net = tflearn.input_data(shape=[None, 6])
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 1, activation='softmax')
net = tflearn.regression(net)
model = tflearn.DNN(net)
model.fit(X_train, Y_train, n_epoch=10, batch_size=16, show_metric=True)

pred = model.predict(X_test)
print pred

最佳答案

使用softmax作为输出中的激活层,确保该层中所有节点的输出总和为 1。由于您只有一个节点,并且输出总和必须为 1,因此根据定义,它将始终输出 1

您永远不应该使用 softmax 作为二元分类任务的激活。更好的选择是 logistic function ,我认为 tensorflow 称之为 sigmoid .

所以而不是

net = tflearn.fully_connected(net, 1, activation='softmax')

尝试

net = tflearn.fully_connected(net, 1, activation='sigmoid')

关于python - Kaggle 泰坦尼克号与 tflearn 神经网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51281917/

相关文章:

python - 如何将我的数据框拆分为不同的数据框?

python - Tensorboard 分析器 : Failed to load libcupti (is it installed and accessible? )

python - 导入错误: cannot import name VarianceThreshold

python - 如何防止 wxPython 子类中的内存泄漏?

在类中使用 Python3 的 functools.singledispatch 的 Pythonic 方式?

Python 请求模块在特定机器上非常慢

python - 使用递归神经网络对图像进行分类

javascript - 在@tensorflow安装文件夹中找不到"tfjs_binding.node"

machine-learning - ignore_const_cols 缺失值

machine-learning - 提取属性时发生意外异常 Open Vino