<jupyter_start><jupyter_text>Data format- Passenger id : int uuid- Survived 0 or 1- Pclass : 1, 2 or 3- Sex : 'male' or 'female' **String only**- Age : has **nan** values, should replace by median age of the rest of the dataset- SibSp : 0,1,2,3,4,5,8- Parch : 0,1,2,3,4,5,6- Ticket : Number or string + number or just string- Fare : Number- Cabin : String + Number or **nan**, some have duplicate entries- Embarked : 'S', 'C', 'Q' or **nan**, **String only**<jupyter_code>avg_age = math.floor(train_data['Age'].mean())
train_data['Age'] = train_data['Age'].fillna(avg_age)
train_data['Embarked'] = train_data['Embarked'].fillna('U')
## remove columns that I don't feel like parsing atm

train_data.drop('Cabin', inplace = True, axis = 1)
train_data.drop('Ticket', inplace=True, axis = 1)
train_data.drop('Name', inplace=True, axis=1)
train_data.drop('PassengerId', inplace=True, axis = 1)<jupyter_output><empty_output><jupyter_text>Encode categorical attributes<jupyter_code>one_hot_sex = pd.get_dummies(train_data['Sex'])  # haha !
one_hot_Embarked = pd.get_dummies(train_data['Embarked'])
train_data.drop('Sex', inplace=True, axis=1)
train_data.drop('Embarked', inplace=True, axis=1)
train_data = train_data.join(one_hot_sex)
train_data = train_data.join(one_hot_Embarked)
train_data.head()
y_train = train_data.pop('Survived')
X_train = train_data

y_train.head()
X_train.head()
bad_data = X_train[X_train.isna().any(axis=1)]
bad_data.head()
X_train.isna().any()<jupyter_output><empty_output><jupyter_text>Convert to Tensorflow model input<jupyter_code>X_train = tf.convert_to_tensor(X_train)
y_train = tf.convert_to_tensor(y_train)
X_train.shape
# normalizer = tf.keras.layers.Normalization(axis=-1)
# normalizer.adapt(X_train)
X_train = tf.linalg.normalize(
    X_train, ord='euclidean', axis = -1
)
X_train = X_train[0]
train_ds = tf.data.Dataset.from_tensors((X_train,y_train))<jupyter_output><empty_output><jupyter_text>Create Model<jupyter_code>def create_non_seq_model():
    input_layer = tf.keras.layers.Input(shape=[11,])
    hidden1 = tf.keras.layers.Dense(10, activation='relu')(input_layer)
    hidden2 = tf.keras.layers.Dense(10, activation='relu')(hidden1)
    concat = tf.keras.layers.Concatenate()([input_layer, hidden2])
    output = tf.keras.layers.Dense(1, activation='softmax')(concat)
    model = tf.keras.Model(inputs=[input_layer], outputs=[output])
    return model
m = create_non_seq_model()
loss_fn = tf.keras.losses.MeanSquaredError()
m.compile(optimizer='adam', loss=loss_fn)
m.summary()<jupyter_output>Model: "model_3"
__________________________________________________________________________________________________
 Layer (type)                   Output Shape         Param #     Connected to                     
==================================================================================================
 input_4 (InputLayer)           [(None, 11)]         0           []                               
                                                                                                  
 dense_9 (Dense)                (None, 10)           120         ['input_4[0][0]']                
                                                                                                  
 dense_10 (Dense)               (None, 10)           110         ['dense_9[0][0]']                
                                                                                                  
 concatenate_3 (Concatenate)    (None, 21)           0           ['input_4[0][0]',          [...]<jupyter_text>Training<jupyter_code>m.fit(train_ds, epochs = 20)<jupyter_output>Epoch 1/20
1/1 [==============================] - 0s 227ms/step - loss: 0.6162
Epoch 2/20
1/1 [==============================] - 0s 2ms/step - loss: 0.6162
Epoch 3/20
1/1 [==============================] - 0s 3ms/step - loss: 0.6162
Epoch 4/20
1/1 [==============================] - 0s 2ms/step - loss: 0.6162
Epoch 5/20
1/1 [==============================] - 0s 3ms/step - loss: 0.6162
Epoch 6/20
1/1 [==============================] - 0s 2ms/step - loss: 0.6162
Epoch 7/20
1/1 [==============================] - 0s 3ms/step - loss: 0.6162
Epoch 8/20
1/1 [==============================] - 0s 2ms/step - loss: 0.6162
Epoch 9/20
1/1 [==============================] - 0s 3ms/step - loss: 0.6162
Epoch 10/20
1/1 [==============================] - 0s 3ms/step - loss: 0.6162
Epoch 11/20
1/1 [==============================] - 0s 3ms/step - loss: 0.6162
Epoch 12/20
1/1 [==============================] - 0s 2ms/step - loss: 0.6162
Epoch 13/20
1/1 [==============================] - 0s 3ms/step - loss: [...]<jupyter_text>On test data<jupyter_code>test_data = pd.read_csv('test.csv')
avg_age = math.floor(train_data['Age'].mean())
test_data['Age'] = test_data['Age'].fillna(avg_age)
test_data['Embarked'] = test_data['Embarked'].fillna('U')

one_hot_sex = pd.get_dummies(test_data['Sex'])  # haha !
one_hot_Embarked = pd.get_dummies(test_data['Embarked'])
test_data.drop('Sex', inplace=True, axis=1)
test_data.drop('Embarked', inplace=True, axis=1)
test_data = test_data.join(one_hot_sex)
test_data = test_data.join(one_hot_Embarked)
test_data.drop('Cabin', inplace = True, axis = 1)
test_data.drop('Ticket', inplace=True, axis = 1)
test_data.drop('Name', inplace=True, axis=1)
test_data.drop('PassengerId',inplace=True, axis=1)
test_data['U'] = 0
test_data.head()
X_test = tf.convert_to_tensor(test_data)
X_test =tf.linalg.normalize(
    X_test, ord = 'euclidean', axis = -1
)
X_test = X_test[0]
X_test.shape
test_ds = tf.data.Dataset.from_tensors(X_test)
preds = m.predict(test_ds)
preds<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2209013484740951, 'fraction_numerical': 0.04240596167494677, 'mean_word_length': 3.5866558177379986, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '96602', 'license': 'MIT', 'n_tokens_mistral': 2113, 'n_tokens_neox': 1915, 'n_words': 355, 'path': 'non_sequential.ipynb', 'repo_name': 'alexandreLamarre/tf-kaggle-titanic', 'size': '5636'}