text_plain_output_1.png
from sklearn.model_selection import train_test_split

from sklearn.neighbors import KNeighborsClassifier

from sklearn.preprocessing import StandardScaler

from sklearn.preprocessing import StandardScaler

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import pandas as pd

dataset = pd.read_csv('../input/train.csv')

X = dataset.iloc[:, [4, 2, 6, 5]].values
y = dataset.iloc[:, 1].values

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
fig.set_size_inches(98.5, 90.5)
ax = fig.add_subplot(999, projection='3d')

i=0
for g , xs ,ys , zs  in X:
    c = y[i]
    i +=1
    if c == 1:
        cc='blue'  #servive
    else:
        cc='yellow'  #died
    if g == 1:
        m = "^"   # male
    else:
        m = "v"   #famle
    
    ax.scatter(xs, ys, zs , c=cc , marker=m)

ax.set_xlabel('class')
ax.set_ylabel('sibsp')
ax.set_zlabel('age')
plt.show()

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

from sklearn.neighbors import KNeighborsClassifier
classifier = KNeighborsClassifier(n_neighbors=4, metric='minkowski', p=2)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)

fig = plt.figure()
fig.set_size_inches(98.5, 90.5)
ax = fig.add_subplot(999, projection='3d')

i=0
for g , xs ,ys , zs  in X_test:
    c = y_test[i]
    if c == 1:
        cc='blue'  #servive
    else:
        cc='red'  #died
    if g == 1:
        m = "^"   # male
    else:
        m = "v"   #famle
    if y_pred[i] == y_test[i]:
        if y_pred[i] == 1:
            cc = 'green'
        else:
            cc = 'yellow'
        m = "+"
    i +=1
    
    ax.scatter(xs, ys, zs , c=cc , marker=m )

ax.set_xlabel('class')
ax.set_ylabel('sibsp')
ax.set_zlabel('age')
plt.show()

realdata = pd.read_csv('../input/test.csv')

X_real = realdata.iloc[:, [3, 1, 5, 4]].values
X_real

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_real = sc.fit_transform(X_real)

y_real_pred = classifier.predict(X_real)
fig = plt.figure()
fig.set_size_inches(98.5, 90.5)
ax = fig.add_subplot(999, projection='3d')
i = 0
for g, xs, ys, zs in X_real:
    c = y_real_pred[i]
    if c == 1:
        cc = 'blue'
    else:
        cc = 'red'
    if g == 1:
        m = '^'
    else:
        m = 'v'
    i += 1
    ax.scatter(xs, ys, zs, c=cc, marker=m)
ax.set_xlabel('class')
ax.set_ylabel('sibsp')
ax.set_zlabel('age')
plt.show()