How to create a dataset object for training and testing using a Dataset class

Hi everyone!
I have this Dataset class:
“”"
class Dataset(Dataset):

# Constructor
def __init__(self, train = True):
    
    data = pd.read_csv('https://s3.us.cloud-object-storage.appdomain.cloud/cf-courses-data/CognitiveClass/DL0110EN/ML03210EN_Final_Assignment/LoLMatchData.csv')
    
    if (train):
        self.x = torch.tensor(data.iloc[0:7903, :].drop(['blueWins'], axis=1).values, dtype=torch.float)
        # standardizing the data
        self.x = (self.x - self.x.mean(dim=0))/self.x.std(dim=0)
        self.y = torch.tensor(data.loc[0:7903, 'blueWins'].values, dtype=torch.float).reshape((7904,1))
        self.len = self.x.shape[0]
    else:
        self.x = torch.tensor(data.iloc[7904:, :].drop(['blueWins'], axis=1).values, dtype=torch.float)
        # standardizing the data
        self.x = (self.x - self.x.mean(dim=0))/self.x.std(dim=0)
        self.y = torch.tensor(data.loc[7904:, 'blueWins'].values, dtype=torch.float).reshape((1975,1))
        self.len = self.x.shape[0]
        

# Get the length
def __len__(self):
    return self.len

# Getter
def __getitem__(self, idx):
    
    x = self.x[idx]
    
    y = self.y[idx]

    return x, y

“”"

I need to use this Dataset class to create a dataset object for training and testing. Not to mention set the training parameter to the correct value.

I would be pleased if anyone could help me with this task.
Thank you in Advance!

Based on your code, you could probably create two different datasets and set the train argument appropriately:

train_dataset = Dataset(train=True)
val_dataset = Dataset(train=False)
train_loader = DataLoader(train_dataset)
val_loader = DataLoader(val_dataset)

Let me know, if I misunderstood the question.