application_vnd.jupyter.stderr_output_1.png
from sklearn.preprocessing import Imputer

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import tflearn

df = pd.read_csv('../input/train.csv')
X = df.copy()

columns = ['Pclass', 'Sex', 'Age', 'SibSp', 'Parch', 'Fare', 'Embarked', 'Survived']
X = X[columns]
for i in columns:
    X = X[~X[i].isnull()]
for i in range(1, 4):
    X['Pclass_' + str(i)] = X['Pclass'] == i
del X['Pclass']
for i in X.Embarked.unique():
    X[i] = X['Embarked'] == i
del X['Embarked']
for i in X.Sex.unique():
    X[i] = X['Sex'] == i
del X['Sex']
y = pd.DataFrame({'Survived': X['Survived'], 'Not Survived': 1 - X['Survived']})
y.shape
del X['Survived']

X = np.array(X, dtype=np.float32)
y = np.array(y, dtype=np.float32)

net = tflearn.input_data(shape=[None, 9])
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net)

model = tflearn.DNN(net)
model.fit(X, y, n_epoch=200, batch_size=16, show_metric=True)

df = pd.read_csv('../input/test.csv')
X_test = df.copy()

columns = ['Pclass', 'Sex', 'Age', 'SibSp', 'Parch', 'Fare', 'Embarked']
X_test = X_test[columns]
for i in range(1, 4):
    X_test['Pclass_' + str(i)] = X_test['Pclass'] == i
del X_test['Pclass']
for i in X_test.Embarked.unique():
    X_test[i] = X_test['Embarked'] == i
del X_test['Embarked']
for i in X_test.Sex.unique():
    X_test[i] = X_test['Sex'] == i
del X_test['Sex']

X_test = np.array(X_test, dtype=np.float32)

from sklearn.preprocessing import Imputer
imputer = Imputer()
X_test = imputer.fit_transform(X_test)

pred = model.predict(X_test)

predict = np.zeros(len(pred))
for i in range(len(pred)):
    if pred[i][1] >= 0.5:
        predict[i] = 1

y_test = pd.read_csv('../input/gender_submission.csv')
y_test = pd.DataFrame({'Survived': y_test['Survived'], 'Not Survived': 1 - y_test['Survived']})
y_test = np.array(y_test, dtype=np.float32)

test = pd.read_csv('../input/test.csv')
my_submission = pd.DataFrame({'PassengerId': test.PassengerId, 'Survived': predict.astype(int)})
my_submission.to_csv('submission.csv', index=False)