These are some of my suggestions


StandardScaler is written in such a way that it assumes the input is a torch.tensor. You use this class in CSVDataset class

CSVDataset class reads the data from a file and stores in pandas dataframe (pd.read_csv). On this data you are using StandardScaler (but it takes input as tensor). So that’s why you were getting multiple error on input types.
One more thing to point out is that in your CSVDataset class, all the variables are np.array or pandas.dataframe. they will only be converted to torch.tensor at the dataloader.

These are my changes
class CSVDataset(Dataset):
    # Load the dataset.
    def __init__(self, file_path, train, transform=None):
        # Read the data into a dataframe.
        df = pd.read_csv(file_path)

        # Store the input & output variables.
        # `.values` will convert the pandas dataframe to numpy array.
        self.train_X = df.iloc[:, 1:-1].values.astype('float32').values
        self.train_Y = df.iloc[:, -1].values.astype('float32').values
        self.test_X = df.iloc[:, 1:-1].values.astype('float32').values
        self.test_Y = np.empty(len(self.test_X)).values
        self.transform = transform

        # call fit on training data.
        self.transform(self.train_X)
        self.train = train

    def __getitem__(self, index):
        if self.train is True:
            X_data = self.train_X[index]
            Y_data = self.train_Y[index]
            if self.transform is not None:
                X_data = self.transform(X_data)
                Y_data = self.transform(Y_data)
            return X_data, Y_data

        else:
            X_data = self.test_X[index]
            if self.transform is not None:
                X_data = self.transform(X_data)
            return X_data

    def __len__(self):
        if self.train is True:
            return len(self.train_Y)
        else:
            return len(self.test_Y)

def train_val_dataset(dataset, val_split=0.2):
    train_idx, val_idx = train_test_split(list(range(len(dataset))), \
        test_size=val_split, shuffle=True, random_state=42)
    train_val_splits = {}
    train_val_splits['train'] = Subset(dataset, train_idx)
    train_val_splits['val'] = Subset(dataset, val_idx)
    return train_val_splits

def test_dataset(dataset):
    test_idx = list(range(len(dataset)))
    test_split = {}
    test_split['test'] = Subset(dataset, test_idx)
    return test_split


################################################################################################
class StandardScaler():
    """Standardize data by removing the mean and scaling to unit variance.
       This object can be used as a transform in PyTorch data loaders.

    Args:
        mean (FloatTensor): The mean value for each feature in the data.
        scale (FloatTensor): Per-feature relative scaling.
    """

    def __init__(self, mean=None, scale=None):
        self.mean_ = mean
        self.scale_ = scale

    def fit(self, sample):
        """Set the mean and scale values based on the sample data.
        """
        # change the function such that it works if `sample` is a `np. array`
        # 1) https://numpy.org/doc/stable/reference/generated/numpy.mean.html -> np.mean
        # 2) https://numpy.org/doc/stable/reference/generated/numpy.std.html -> np.std
        self.mean_ = sample.mean(0, keepdims=True)
        # changed the index to 0 (as you want to calculate std over samples)
        self.scale_ = sample.std(0, keepdims=True)
        return self

    def __call__(self, sample):
        return (sample - self.mean_)/self.scale_

    def inverse_transform(self, sample):
        """Scale the data back to the original sample space.
        """
        return sample * self.scale_ + self.mean_
################################################################################################


# Create transform function to pass into CSVDataset class.
# transform = transforms.Compose([transforms.ToTensor(), StandardScaler(mean=0, scale=1)])

transform = StandardScaler()

"""
transform = StandardScaler()
transform = StandardScaler(mean=0, scale=1)
"""

# Test CSVDataset class definition & print train/test dataset sizes.
dataset = CSVDataset(file_path, train=True, transform=transform)
print(dataset.train_X)
print()

print(dataset.train_Y)
print()

print(dataset.test_X)
print()

# Print the length of the entire passed dataset.
print("Dataset Length:", len(dataset))
print()


# Pass train/validation splits into PyTorch DataLoader functions.
def cycle(iterable):
    while True:
        for x in iterable:
            yield x

train_loader = DataLoader(train_val_splits['train'], batch_size=64, shuffle=True, num_workers=0, pin_memory=True)
train_iter = iter(cycle(train_loader))

val_loader = DataLoader(train_val_splits['val'], batch_size=64, shuffle=True, num_workers=0, pin_memory=True)
val_iter = iter(cycle(val_loader))

# Acquire & print test batch of training/validation data.
dataiter = iter(train_loader)
train_batch = dataiter.next()
print(train_batch)
print()

dataiter2 = iter(val_loader)
val_batch = dataiter2.next()
print(val_batch)
print()

My changes are not the only way to do. do let me know if you get any error’s while running the code.