Titanic - Neural Network - Two hidden layers – 5 units ReLU and 3 units tanh

Want to build a model neural network model using PyTorch library.

The model should use two hidden layers: the first hidden layer must contain 5 units using the ReLU activation function; the second layer must contain 3 units using tanh activation function.

Want to use the Titanic train dataset I have. Want to use ONLY the train dataset (.CVV) and split the dataset (i.e., train.csv) to a training set (80% samples) and a testing set
(20% samples)

Don’t know how to define model definition for 2 hidden layers which are ReLU and tanh with 5 and 3 units (nucleus) respectively.

A sample code would really help. Step by step code including standard methods implemented (data cleansing, normalizing, Model training, testing, etc.) would really help me to learn this.

I am using a Jupyter notebook.


The CIFAR10 tutorial might be a good starter as it walks you through the data loading pipeline, defining a custom model, and training it.

Thank you so much for referring good start.

I am getting the below error. How this can be resolved?

Lets Split the Train Dataset into training set (80%) and Testing set (20%)

X = train.drop(‘Survived’, axis=1).values
y = train[‘Survived’].values

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

X_train = torch.FloatTensor(X_train)
X_test = torch.FloatTensor(X_test)
y_train = torch.LongTensor(y_train)
y_test = torch.LongTensor(y_test)

TypeError Traceback (most recent call last)
C:\Users\JAYPAT~1\AppData\Local\Temp/ipykernel_5072/502746771.py in
6 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
----> 8 X_train = torch.FloatTensor(X_train)
9 X_test = torch.FloatTensor(X_test)
10 y_train = torch.LongTensor(y_train)

TypeError: can’t convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.