text_plain_output_1.png
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis

from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier

from sklearn.metrics import accuracy_score

from sklearn.naive_bayes import GaussianNB

from sklearn.neighbors import KNeighborsClassifier

from sklearn.tree import DecisionTreeClassifier

import numpy as np # linear algebra

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

train_data = pd.read_csv('../input/train.csv')
test_data = pd.read_csv('../input/test.csv')
files_listing = test_data.PassengerId
test_labels = pd.read_csv('../input/gender_submission.csv')

labels_test = test_labels.values
labels_test = labels_test[:, 1]
test_data = test_data.drop(['Name', 'SibSp', 'Parch', 'Ticket', 'Fare', 'Cabin', 'Embarked'], axis=1)
test_data.Age = test_data.Age.fillna(np.mean(train_data.Age))
test_data.Sex = test_data.Sex.apply(lambda x: 1 if x == 'male' else 0)
test_data = test_data.values
test_data = test_data[:, 1:]
features_test = test_data

train_data = train_data.drop(['Name', 'SibSp', 'Parch', 'Ticket', 'Fare', 'Cabin', 'Embarked'], axis=1)

train_data['Age'] = train_data['Age'].fillna(np.mean(train_data.Age))
train_data['Sex'] = train_data['Sex'].apply(lambda x: 1 if x == 'male' else 0)

features_all = train_data.values
labels_all = features_all[:, 1]
features_all = features_all[:, 2:]

from sklearn.metrics import accuracy_score
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC, LinearSVC, NuSVC
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
classifiers = [KNeighborsClassifier(), AdaBoostClassifier(), RandomForestClassifier(), GaussianNB(), LinearDiscriminantAnalysis(), GradientBoostingClassifier(), DecisionTreeClassifier()]
uni, cnt = np.unique(labels_test, return_counts=True)
res_cols = ['Name', 'Accuracy']
result = pd.DataFrame(columns=res_cols)
print('Actual Value of the result ', dict(zip(uni, cnt)))
for clf in classifiers:
    clf.fit(features_all, labels_all)
    print('-' * 50)
    name = clf.__class__.__name__
    print(name)
    pred_train = clf.predict(features_test)
    acc = accuracy_score(labels_test, pred_train)
    print('Result ->', acc * 100, '%')
    frame = pd.DataFrame([[name, acc * 100]], columns=res_cols)
    result = result.append(frame)
print('-' * 50)