text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

train_df = pd.read_csv('../input/spaceship-titanic/train.csv')

test_df = pd.read_csv('../input/spaceship-titanic/test.csv')

space_torr = train_df.corr()

sns.set(font_scale=1.5)
colors = sns.color_palette('Paired')
explode = (0.05, 0.05)

exp_feats = ["RoomService", "FoodCourt", "ShoppingMall", "Spa", "VRDeck"]

fig=plt.figure(figsize=(10,20))
for i, var_name in enumerate(exp_feats):
    ax=fig.add_subplot(5,2,2*i+1)
    sns.histplot(data=train_df, x=var_name, axes=ax, bins=30, kde=False, hue='Transported')
    ax.set_title(var_name)
    
    ax=fig.add_subplot(5,2,2*i+2)
    sns.histplot(data=train_df, x=var_name, axes=ax, bins=30, kde=True, hue='Transported')
    plt.ylim([0,100])
    ax.set_title(var_name)
fig.tight_layout()  
plt.show()

cat_feats = ["HomePlanet", "CryoSleep", "Destination", "VIP"]

fig = plt.figure(figsize=(10, 20))
sns.set(font_scale=1.2)

for i, var_name in enumerate(cat_feats):

    ax = fig.add_subplot(4, 1, i + 1)
    sns.countplot(data=train_df, x=var_name, axes=ax, hue="Transported")
    ax.set_title(var_name)

fig.tight_layout()
plt.show()

train_df['Total_expense'] = train_df.iloc[:, -7:-2].sum(axis=1)
train_df['Spent_money'] = train_df['Total_expense'].apply(lambda x: False if x == 0 else True)
test_df['Total_expense'] = test_df.iloc[:, -7:-2].sum(axis=1)
test_df['Spent_money'] = test_df['Total_expense'].apply(lambda x: False if x == 0 else True)

train_df.loc[train_df['Family_size'] > 100, 'Family_size'] = np.nan
test_df.loc[test_df['Family_size'] > 100, 'Family_size'] = np.nan

fig = plt.figure(figsize=(30, 15))
sns.set(font_scale=2)
sns.countplot(data=train_df, x='Spent_money', hue='Transported')
plt.xlabel('Spent_money', fontsize=40)
plt.ylabel('Nombre de passagers', fontsize=40)