-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCryptoDataset.py
More file actions
33 lines (26 loc) · 1.06 KB
/
CryptoDataset.py
File metadata and controls
33 lines (26 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from torch.utils.data import Dataset
import torch
class CryptoDataset(Dataset): #torch.utils.data.Dataset
"""This class is the dataset class which is used to load data for training the LSTM
to forecast timeseries data
"""
def __init__(self, inputs, outputs):
"""Initialize the class with instance variables
Args:
inputs ([list]): [A list of tuples representing input parameters]
outputs ([list]): [A list of floats for the stock price]
"""
self.inputs = inputs
self.outputs = outputs
def __len__(self):
"""Returns the total number of samples in the dataset
"""
return len(self.outputs)
def __getitem__(self, idx):
"""Given an index, it retrieves the input and output corresponding to that index and returns the same
Args:
idx ([int]): [An integer representing a position in the samples]
"""
x = torch.FloatTensor(self.inputs[idx])
y = torch.FloatTensor([self.outputs[idx]])
return (x, y)