text_plain_output_2.png text_plain_output_1.png image_output_1.png
from sklearn.model_selection import cross_val_score

from sklearn.naive_bayes import GaussianNB

from sklearn.preprocessing import LabelEncoder

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

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

dataset.dtypes

def clean_data(dataset):
    data = dataset.dropna()
    data = data.drop('PassengerId', axis=1)
    data = data.drop('Name', axis=1)
    data = data.drop('Ticket', axis=1)
    return data

def encode_categorical_feautures(dataset):
    for coloumns in dataset.columns:
        enc = LabelEncoder()
        enc.fit(dataset[coloumns])
        dataset[coloumns] = enc.fit_transform(dataset[coloumns])
    return dataset

dataset = clean_data(dataset)
dataset = encode_categorical_feautures(dataset)

train_y = dataset['Survived']
train_x = dataset.drop('Survived', axis=1)

clf = GaussianNB()
clf.fit(train_x, train_y)
scores = cross_val_score(clf, train_x, train_y, cv=5)
print('Naive Bayes Classifier :\n')
print('Accuracy: %0.2f (+/- %0.2f)' % (scores.mean(), scores.std() * 2))