<jupyter_start><jupyter_text>Modeling procedure for structured data<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import tensorflow as tf
from tensorflow.keras import models, layers
print('TensorFlow version:', tf.__version__)
df_train = pd.read_csv('../data/titanic/train.csv')
df_test = pd.read_csv('../data/titanic/test.csv')
df_train.head(10)
df_test.head(10)
print(df_train.shape)
print(df_test.shape)
%config InlineBackend.figure_format = 'png'
plt.figure(figsize=(6, 4))
ax = df_train.Survived.value_counts().plot(kind = 'bar', color = 'orange')

ax.set_xlabel('Survived', fontsize = 10)
ax.set_ylabel('Counts', fontsize = 10)
plt.show()
%config InlineBackend.figure_format = 'png'
ax = df_train['Age'].plot(kind = 'hist', bins = 30, color= 'purple', edgecolor = 'black', figsize = (12,8), fontsize= 15)

ax.set_ylabel('Frequency',fontsize = 15)
ax.set_xlabel('Age',fontsize = 15)
plt.show()
%matplotlib inline
%config InlineBackend.figure_format = 'png'

ax = df_train.query('Survived == 0')['Age'].plot(kind = 'density', figsize = (12,8), fontsize=15)
ax = df_train.query('Survived == 1')['Age'].plot(kind = 'density', figsize = (12,8), fontsize=15)

ax.legend(['Survived==0 (Not survived)', 'Survived==1 (Survived)'],fontsize = 12)
ax.set_ylabel('Density',fontsize = 15)
ax.set_xlabel('Age',fontsize = 15)
plt.show()
df_train.isna().sum()
df_test.isnull().sum()
def preprocesing(dfdata):
    dfresult = pd.DataFrame()
    
    #Pclass
    dfpclass = pd.get_dummies(data = dfdata, columns = Pclass)
    dfPclass.columns = ['Pclass_' +str(x) for x in dfPclass.columns]
    dfresult = pd.concat([dfresult, Pclass], axis=1)
    
    #Sex
    dfSex = pd.get_dummies(dfdata['Sex'])
    dfresult = pd.concat([dfresult,dfSex],axis = 1)
    
    #Age
    dfresult['Age'] = dfdata['Age'].fillna(0)
    dfresult['Age_null'] = pd.isna(dfdata['Age']).astype('int32')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17333333333333334, 'fraction_numerical': 0.02358974358974359, 'mean_word_length': 5.525083612040134, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '219292', 'license': 'DOC', 'n_tokens_mistral': 793, 'n_tokens_neox': 743, 'n_words': 140, 'path': 'english/modeling_procedure_for_structured_data.ipynb', 'repo_name': 'madhukumble/tensorflow2_tutorials', 'size': '1950'}