I took only positive samples and trained the generator and discriminator. The discriminator predicts anomlay or normal with an accuracy of 52 percent. I would appreciate some help to improve performance: This is the code for it:

```
train_data_length = df.shape[0]
train_labels = torch.zeros(train_data_length)
train_data = torch.tensor(df.values)
train_set = [
(train_data[i], train_labels[i]) for i in range(train_data_length)
]
batch_size = 40
train_loader = torch.utils.data.DataLoader(
train_set, batch_size=batch_size, shuffle=True
)
class Discriminator(nn.Module):
def __init__(self):
super().__init__()
self.model = nn.Sequential(
nn.Linear(118, 512),
nn.ReLU(),
nn.Dropout(0.3),
nn.Linear(512, 256),
nn.ReLU(),
nn.Dropout(0.3),
nn.Linear(256, 128),
nn.ReLU(),
nn.Dropout(0.3),
nn.Linear(128, 64),
nn.ReLU(),
nn.Dropout(0.3),
nn.Linear(64, 1),
nn.Sigmoid(),
)
def forward(self, x):
output = self.model(x)
return output
discriminator = Discriminator()
class Generator(nn.Module):
def __init__(self):
super().__init__()
self.model = nn.Sequential(
nn.Linear(118, 256),
nn.ReLU(),
nn.Linear(256, 512),
nn.ReLU(),
nn.Linear(512, 118),
)
def forward(self, x):
x = x.view(x.size(0), 118)
output = self.model(x)
return output
generator = Generator()
lr = 0.0001
num_epochs = 100
loss_function = nn.BCELoss()
optimizer_discriminator = torch.optim.Adam(discriminator.parameters(), lr=lr)
optimizer_generator = torch.optim.Adam(generator.parameters(), lr=lr)
for epoch in range(num_epochs):
for n, (real_samples, _) in enumerate(train_loader):
# Data for training the discriminator
real_samples_labels = torch.ones((batch_size, 1))
latent_space_samples = torch.randn((batch_size, 118))
generated_samples = generator(latent_space_samples)
generated_samples_labels = torch.zeros((batch_size, 1))
all_samples = torch.cat((real_samples, generated_samples))
all_samples_labels = torch.cat(
(real_samples_labels, generated_samples_labels)
)
# Training the discriminator
discriminator.zero_grad()
all_samples = all_samples.float()
output_discriminator = discriminator(all_samples)
loss_discriminator = loss_function(
output_discriminator, all_samples_labels)
loss_discriminator.backward()
optimizer_discriminator.step()
# Data for training the generator
latent_space_samples = torch.randn((batch_size, 118))
# Training the generator
generator.zero_grad()
generated_samples = generator(latent_space_samples)
output_discriminator_generated = discriminator(generated_samples)
loss_generator = loss_function(
output_discriminator_generated, real_samples_labels
)
loss_generator.backward()
optimizer_generator.step()
# Show loss
if epoch % 10 == 0 and n == batch_size - 1:
print(f"Epoch: {epoch} Loss D.: {loss_discriminator}")
print(f"Epoch: {epoch} Loss G.: {loss_generator}")
pred = discriminator(test_data)
y_pred = pred.detach().numpy()
from sklearn.metrics import accuracy_score
threshold = 0.5
predicted_labels = (y_pred >= threshold).astype(int)
# Calculate accuracy
accuracy = accuracy_score(y, predicted_labels)
print(f'Accuracy: {accuracy}')
```

Thank you for your help!