text_plain_output_1.png
from plotly.subplots import make_subplots

import pandas as pd

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

import plotly.graph_objects as go

train = pd.read_csv('../input/spaceship-titanic/train.csv')
test = pd.read_csv('../input/spaceship-titanic/test.csv')
submission = pd.read_csv('../input/spaceship-titanic/sample_submission.csv')
RANDOM_STATE = 12
FOLDS = 5
STRATEGY = 'median'

train.count()

test.count()

test.isna().sum().sort_values(ascending=False)

train.drop(columns=['PassengerId'], inplace=True)
test.drop(columns=['PassengerId'], inplace=True)
TARGET = 'Transported'
FEATURES = []
for col in train.columns:
    if col != TARGET:
        FEATURES.append(col)

train.iloc[:, :-1].describe().T.sort_values(by='mean', ascending=False)

test_null = pd.DataFrame(test.isna().sum())

test.isna().sum()

test_null = test_null.sort_values(by=0, ascending=False)

train_null = pd.DataFrame(train.isna().sum())

train_null = train_null.sort_values(by=0, ascending=False)[:-1]

fig = make_subplots(rows=1, cols=2,
                    column_titles = ["Train Data", "Test Data",],
                    x_title = "Missing Values")

fig.add_trace(go.Bar(x=train_null[0], y=train_null.index, orientation='h', marker=dict(color=[n for n in range(12)])), 1, 1)
fig.add_trace(go.Bar(x=test_null[0], y=test_null.index, orientation='h', marker=dict(color=[n for n in range(12)])), 1, 2)
fig.update_layout(showlegend=False, title_text='Column wise Null Value Distribution', title_x=0.5)

train.dtypes

df = pd.concat([train[FEATURES], test[FEATURES]], axis=0)
text_features = ['Cabin', 'Name']
cat_features = [col for col in FEATURES if df[col].nunique() < 25 and col not in text_features]
cont_features = [col for col in FEATURES if df[col].nunique() >= 25 and col not in text_features]
del df
print(f'Total number of features: {len(FEATURES)}')
print(f'Number of categorical features: {len(cat_features)}')
print(f'Number of continuos features: {len(cont_features)}')
print(f'Number of text features: {len(text_features)}')
labels = ['Categorical', 'Continuous', 'Text']
values = [len(cat_features), len(cont_features), len(text_features)]
fig = go.Figure(data=[go.Pie(labels=labels, values=values, pull=[0.1, 0, 0])])
fig.show()