I am doing the Kaggle competition “Titanic - Machine Learning from Disaster”, my code:
“# 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
!pip install tensorflow
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# 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

import os
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
train_data = pd.read_csv(”/kaggle/input/titanic/train.csv")
test_data = pd.read_csv(“/kaggle/input/titanic/test.csv”)
train_data.head(100)
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler

features = [‘PassengerId’, ‘Survived’, ‘Pclass’,‘Name’,‘Sex’,‘Age’,‘SibSp’,‘Parch’,‘Ticket’,‘Fare’,‘Cabin’,‘Embarked’]
X = pd.get_dummies(train_data[features])
y = train_data[‘Survived’]

# Splitting the training data for validation
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=42)

# It’s generally a good idea to scale your data for neural networks
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_val_scaled = scaler.transform(X_val)
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout

model = Sequential([
Dense(32, activation=‘relu’, input_shape=(X_train_scaled.shape[1],)),
Dropout(0.5),
Dense(32, activation=‘relu’),
Dropout(0.5),
Dense(32, activation=‘relu’),
Dropout(0.5),
Dense(1, activation=‘sigmoid’)
])

model.compile(optimizer=‘adam’,
loss=‘binary_crossentropy’,
metrics=[‘accuracy’])

history = model.fit(X_train_scaled, y_train, epochs=100, validation_data=(X_val_scaled, y_val),
verbose=1, batch_size=2)
# Scale the test data
X_test = pd.get_dummies(test_data[features])
X_test_scaled = scaler.transform(X_test)

# Prediction
test_predictions = model.predict(X_test_scaled)
test_predictions = (test_predictions > 0.5).astype(int).reshape(-1)

# Preparing for submission
output = pd.DataFrame({‘PassengerId’: test_data.PassengerId, ‘Survived’: test_predictions})
output.to_csv(‘neural_network_submission.csv’, index=False)
print(“Your neural network submission was successfully saved!”)
"
However:Epoch 1/100
/opt/conda/lib/python3.10/site-packages/keras/src/layers/core/dense.py:86: UserWarning: Do not pass an input_shape/input_dim argument to a layer. When using Sequential models, prefer using an Input(shape) object as the first layer in the model instead.
the output of the layer (its “activation”).
92/356 ━━━━━━━━━━━━━━━━━━━━ 0s 2ms/step - accuracy: 0.6802 - loss: nan
W0000 00:00:1714140438.775364 112 graph_launch.cc:671] Fallback to op-by-op mode because memset node breaks graph update
336/356 ━━━━━━━━━━━━━━━━━━━━ 0s 2ms/step - accuracy: 0.6417 - loss: nan
W0000 00:00:1714140439.695673 113 graph_launch.cc:671] Fallback to op-by-op mode because memset node breaks graph update