application_vnd.jupyter.stderr_output_2.png application_vnd.jupyter.stderr_output_4.png application_vnd.jupyter.stderr_output_3.png application_vnd.jupyter.stderr_output_1.png
from sklearn.neighbors import KNeighborsClassifier

import numpy as np

import numpy as np # linear algebra

import pandas as pd

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

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

"""
Takeaways
Age is null for some rows
Cabin is almost always null
Embarked is null for only 2 rows
"""

"""
Takeaways
Fare is null for one row
Cabin null for most
Age null for some
"""

X_train = train_df[['Pclass', 'Sex', 'Age', 'Parch', 'Fare', 'Embarked', 'Child', 'Family', 'CabinStartsWith']].values
Y_train = train_df[['Survived']].values
X_test = test_df[['Pclass', 'Sex', 'Age', 'Parch', 'Fare', 'Embarked', 'Child', 'Family', 'CabinStartsWith']].values

knn = KNeighborsClassifier(n_neighbors=3)
knn.fit(X_train, Y_train)
Y_pred_knn = knn.predict(X_test)
knn.score(X_train, Y_train)