import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.neural_network import MLPClassifier
import sklearn.tree as tree
from sklearn.metrics import confusion_matrix
from sklearn.ensemble import RandomForestClassifier

names = ['Pclass','Sex','Age','Survived']

df = pd.read_csv('TitanicFields.csv', header=None, names=names)
X = np.array(df.iloc[:, 0:2]) 	
y = np.array(df['Survived'])

# split the data into train and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30)

model = RandomForestClassifier()
model.fit(X_train, y_train)
pred = model.predict(X_test)
print ('Accuracy Score: ', accuracy_score(y_test, pred))
print('\nConfusion Matrix\n', confusion_matrix(y_test, pred))
