Hello everyone and thanks in advance for taking the time to read through my issue. I’m currently trying to tackle regression on a Time Series (Bitcoin prices in the last 5 years). To spare you all the boring details my dataset is as follows after preprocessing:
0 0.000846
1 0.001299
2 0.002159
3 0.001813
4 0.001773
...
1822 0.680117
1823 0.689799
1824 0.687676
1825 0.690270
1826 0.715508
Name: Close, Length: 1827, dtype: float64
This is basically the Closing price for every day in the past 5 years (its normalized based on the entire dataset then extracted). From this, I want to create a “sliding window” dataset so I can use the previous 50 days to predict the price of the next day. My custom dataset is as follows:
class TimeSeriesDataset(Data.Dataset):
def __init__(self, data, window):
self.data = torch.Tensor(data.values)
self.window = window
def __getitem__(self, index):
return (self.data[index:index+self.window], self.data[index+self.window])
def __len__(self):
return self.data.__len__() - (self.window)
I’ve manually split the data into training and testing (80% to training) and my network architecture is this:
self.hidden1 = torch.nn.Linear(50, 25) # hidden layer
self.hidden2 = torch.nn.Linear(25, 25) # hidden layer
self.out = torch.nn.Linear(25, 1) # output layer
and these are my training and testing methods:
def train(dataset, model, loss_fn, optimizer):
size = len(dataset)
model.train()
for batch, (X, y) in enumerate(dataset):
X, y = X.to(device), y.to(device)
# Compute prediction error
pred = model(X).squeeze(-1)
loss = loss_fn(pred, y)
# Backpropagation
optimizer.zero_grad()
loss.backward()
optimizer.step()
if batch % 100 == 0:
loss, current = loss.item(), batch
print(f"loss: {loss:>7f} Batch: [{current:>5d}/{size:>5d}]")
def test(dataset, model, loss_fn):
size = len(dataset)
num_batches = len(dataset) - 50
model.eval()
test_loss, correct = 0, 0
with torch.no_grad():
for X, y in dataset:
X, y = X.to(device), y.to(device)
pred = model(X).squeeze(-1)
test_loss += loss_fn(pred, y).item()
testing_acc = torch.sum(pred == y)
test_loss /= num_batches
print(f"Test Error: \n Accuracy: {testing_acc}%, Avg loss: {test_loss:>8f} \n")
If I now run this for 20 epochs I notice that on every epoch the loss drops really low, however my accuracy is always 0% because none of my predicted values match the labels.
I figured that I wouldnt be able to predict the price with good accuracy (because if I could then I could beat the market I guess ?) but 0% seems way too low (Or that something’s wrong) especially when loss is dropping. Am I calculating this the wrong way ? What can I try ?
Thanks again and sorry for the long post.