Hi,
I’m programming a neural network that should give exact output if a human is sick or healthy. Given are 250 pieces of data with 5 properties and then the resulting state of health. Based on my program I could achieve 88% accuracy. How can i improve it? Here is the code:
import torch
import numpy as np
import torch.nn as nn
def train(M):
n_steps = 60
learning_rate = 0.01
input_size = 5
output_size = 1
X = M[:, :-1].astype(np.float32)
y = M[:, -1].astype(np.float32)
X = torch.from_numpy(X)
y = torch.from_numpy(y)
feature_means = torch.mean(X, dim=0)
class Model(nn.Module):
def __init__(self, input_size):
super().__init__()
neur = 15
self.layers = nn.Sequential(
nn.Linear(input_size, neur),
nn.PReLU(),
nn.Linear(neur, neur),
nn.Linear(neur, neur),
nn.ReLU(),
nn.Linear(neur, neur),
nn.LogSigmoid(),
nn.Linear(neur, neur),
nn.ReLU(),
nn.PReLU(),
nn.Linear(neur, neur),
nn.Tanhshrink(),
nn.ReLU(),
nn.Linear(neur, neur),
nn.ReLU(),
nn.Linear(neur, output_size),
)
def forward(self, x):
x = x - feature_means
out = self.layers(x)
return out
model = Model(input_size)
criterion = nn.BCEWithLogitsLoss()
optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)
for e in range(n_steps):
outputs = model.forward(X)[:, 0]
cost = criterion(outputs, y)
optimizer.zero_grad()
cost.backward()
optimizer.step()
pred_labels = outputs > 0
is_correct = torch.eq(pred_labels, y.byte()).float()
accuracy = torch.mean(is_correct).item()
return model
Thanks for your help