iam trying to build a neural network to classify survival in titanic dataset
but i keep getting this errors when i run the neural network
Expected object of scalar type Double but got scalar type Float for argument
optimizer = optim.SGD(model.parameters(), lr=0.003)
epochs = 3
print_every = 40
steps = 0
for e in range(epochs):
running_loss = 0
for data, labels in zip(X_train,y_train):
steps += 1
optimizer.zero_grad()
# Forward and backward passes
output = model.forward(data)
loss = criterion(output, labels)
loss.backward()
optimizer.step()
running_loss += loss.item()
if steps % print_every == 0:
print("Epoch: {}/{}... ".format(e+1, epochs),
"Loss: {:.4f}".format(running_loss/print_every))
that’s the code of training
and that’s my network
class Network (nn.Module):
def __init__(self):
super().__init__()
self.fc1 = nn.Linear(7,5)
self.fc2 = nn.Linear(4,3)
self.fc3=nn.Linear(3,2)
def forward(self,x):
x=self.fc1(x)
x=F.relu(x)
x=self.fc2(x)
x=F.relu(x)
x=self.fc3(x)
x=F.sigmoid(x,dim=1)
return x
model= Network()
i’m playing around with the pytorch api to learn so i’m still a begginer