# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
from IPython.display import display
import random
import os
import seaborn as sns
import matplotlib.pyplot as plt
# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
def load_data():
    training_data = pd.read_csv('/kaggle/input/titanic/train.csv')
    test_data = pd.read_csv('/kaggle/input/titanic/test.csv')
    return training_data, test_data
    
training_data, test_data = load_data()
display(training_data.head())
display(test_data.head())
display(training_data.isnull().sum())
display(training_data.info())
"""
# **Survived**
"""
f, ax = plt.subplots(1,1,figsize=(10, 6))
sns.countplot(training_data.Survived, ax=ax)
ax.set_title('Survived')
"""
# **Sex**
"""
f, ax = plt.subplots(1,3,figsize=(15, 6))
sns.countplot(training_data.Sex, ax=ax[0])
sns.countplot(training_data.Sex, hue=training_data.Survived, ax=ax[1])
ax[1].set_title('Sex <-->Survived')
training_data[['Sex', 'Survived']].groupby(['Sex']).mean().plot.bar(ax=ax[2])
ax[2].set_title('Survival rate')
"""
# **Pclass**
"""
f, ax = plt.subplots(1,3,figsize=(15, 6))
sns.countplot(training_data.Pclass, ax=ax[0])
sns.countplot(training_data.Pclass, hue=training_data.Survived, ax=ax[1])
ax[1].set_title('Pclass <-->Survived')
training_data[['Pclass', 'Survived']].groupby(['Pclass']).mean().plot.bar(ax=ax[2])
ax[2].set_title('Survival rate')
"""
# **Age**
"""
training_data[['Age']].describe()
f, ax = plt.subplots(1,3,figsize=(20, 6))
training_data[['Age']].plot.hist(ax=ax[0],bins=20,edgecolor='black',color='blue')
#training_data[['Age', 'Survived']].groupby(['Age']).mean().plot.hist(ax=ax[1],bins=20,edgecolor='black',color='red')
training_data[training_data['Survived']==0].Age.plot.hist(ax=ax[1],bins=20,edgecolor='black',color='red')
ax[1].set_title('Survived= 0')
ax[1].set_xticks(list(range(0,85,5)))
training_data[training_data['Survived']==1].Age.plot.hist(ax=ax[2],color='green',bins=20,edgecolor='black')
ax[2].set_title('Survived= 1')
ax[2].set_xticks(list(range(0,85,5)))
"""
# **Embarked**
"""
f, ax = plt.subplots(1,1,figsize=(10, 6))
sns.countplot(training_data.Embarked, hue=training_data.Survived, ax=ax)
ax.set_title('Embarked <-->Survived')
def flip_coin_model(test_data):
    data_size = len(test_data)
    return [random.randint(0, 1) for i in range(0, data_size)]
    
def submit_predictions(test_data, predictions):
    output = pd.DataFrame({'PassengerId': test_data.PassengerId, 'Survived': predictions})
    output.to_csv('submission.csv', index=False)
    print("Your submission was successfully saved!")
predictions = flip_coin_model(test_data)
submit_predictions(test_data, predictions)