I have a tabular dataset , where I have to perform multi-label classfication . For that , I am unable to figure out how to write its custom dataset class for 100 target columns
e.g. if its like 5 - 10 target classes I can write like this -->
from torch.utils.data import Dataset
import torch
class for_5_target_columns(Dataset):
def __init__(self, tabular_data , is_valid):
self.tabular_data = tabular_data
self.1st_target_value = tabular_data.1st_target_value.values
self.2nd_target_value = tabular_data.2nd_target_value.values
self.3rd_target_value = tabular_data.3rd_target_value.values
self.4th_target_value= tabular_data.4th_target_value.values
self.5th_target_value = tabular_data.5th_target_value.values
def __len__(self):
return len(self.tabular_data)
def __getitem__(self, index):
tabular_data = self.tabular_data.iloc[:,:]
X = tabular_data[training_input.columns()] #training_input.columns() represents column names of X_train
X = X.values[index]
return {
'tabular_data' : torch.tensor(X, dtype = torch.float) ,
'1st_target_value' : torch.tensor(self.1st_target_value[index], dtype = torch.float),
'2nd_target_value' : torch.tensor(self.2nd_target_value[index], dtype = torch.float),
'3rd_target_value' : torch.tensor(self.3rd_target_value[index], dtype = torch.float),
'4th_target_value' : torch.tensor(self.4th_target_value[index], dtype = torch.float),
'5th_target_value' : torch.tensor(self.5th_target_value[index], dtype = torch.float)
}
How to achieve the same for 100 target columns having different column names ?