text_plain_output_1.png image_output_1.png
from sklearn import datasets, svm, cross_validation, tree, preprocessing, metrics

import numpy as np

import pandas as pd

titanic_df = pd.read_csv('../input/train.csv', dtype={'Age': np.float64})
test_df = pd.read_csv('../input/test.csv', dtype={'Age': np.float64})

test_df.count()

test_df = test_df.drop(['Cabin'], axis=1)

test_df = test_df.dropna()

test_df.count()

def preprocess_titanic_df(df):
    processed_df = df.copy()
    le = preprocessing.LabelEncoder()
    processed_df.Sex = le.fit_transform(processed_df.Sex)
    processed_df.Embarked = le.fit_transform(processed_df.Embarked)
    processed_df = processed_df.drop(['Name', 'Ticket'], axis=1)
    return processed_df

processed_test_df = preprocess_titanic_df(test_df)
processed_test_df.count()
processed_test_df