Your code snippet doesn’t seem to include all definitions, as e.g. self.labels is not defined in the __init__ method. Based on the error message it seems self.labels (or any other missing code) is a pandas.DataFrame, which is raising this indexing issue, so you would have to make sure the length of this DataFrame matches the length of the dataset.