text_plain_output_1.png
from sklearn import cross_validation

from sklearn.linear_model import LogisticRegression

from subprocess import check_output

import numpy as np # linear algebra

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

import numpy as np
import pandas as pd
from subprocess import check_output
titanic = pd.read_csv('../input/train.csv')

titanic.loc[titanic['Sex'] == 'male', 'Sex'] = 0

titanic.loc[titanic['Sex'] == 'female', 'Sex'] = 1

titanic.loc[titanic['Embarked'] == 'S'] = 0
titanic.loc[titanic['Embarked'] == 'C'] = 1
titanic.loc[titanic['Embarked'] == 'Q'] = 2

from sklearn.linear_model import LinearRegression
from sklearn.cross_validation import KFold
predictors = ['Pclass', 'Sex', 'Age', 'SibSp', 'Embarked', 'Fare']

from sklearn import cross_validation
from sklearn.linear_model import LogisticRegression
alg = LogisticRegression(random_state=1)
accuracy = cross_validation.cross_val_score(alg, titanic[predictors], titanic['Survived'], cv=3)
mean = np.mean(accuracy)
titanic_test = pd.read_csv('../input/test.csv')
titanic_test['Age'] = titanic_test['Age'].fillna(titanic['Age'].median())
titanic_test['Fare'] = titanic_test['Fare'].fillna(titanic_test['Fare'].median())
titanic_test.loc[titanic_test['Sex'] == 'male', 'Sex'] = 0
titanic_test.loc[titanic_test['Sex'] == 'female', 'Sex'] = 1
titanic_test['Embarked'] = titanic_test['Embarked'].fillna('S')
titanic_test.loc[titanic_test['Embarked'] == 'S', 'Embarked'] = 0
titanic_test.loc[titanic_test['Embarked'] == 'C', 'Embarked'] = 1
titanic_test.loc[titanic_test['Embarked'] == 'Q', 'Embarked'] = 2
alg = LogisticRegression(random_state=1)
alg.fit(titanic[predictors], titanic['Survived'])
predictions = alg.predict(titanic_test[predictors])
print(len(predictions))