bugfix in preprocessing standardize

This commit is contained in:
Alejandro Moreo Fernandez 2024-07-10 16:58:01 +02:00
parent 2034845988
commit b4571d96c7
1 changed files with 8 additions and 3 deletions

View File

@ -90,12 +90,17 @@ def standardize(dataset: Dataset, inplace=False):
:class:`quapy.data.base.Dataset` is to be returned :class:`quapy.data.base.Dataset` is to be returned
:return: an instance of :class:`quapy.data.base.Dataset` :return: an instance of :class:`quapy.data.base.Dataset`
""" """
s = StandardScaler(copy=not inplace) s = StandardScaler()
training = s.fit_transform(dataset.training.instances) train, test = dataset.train_test
test = s.transform(dataset.test.instances) std_train_X = s.fit_transform(train.X)
std_test_X = s.transform(test.X)
if inplace: if inplace:
dataset.training.instances = std_train_X
dataset.test.instances = std_test_X
return dataset return dataset
else: else:
training = LabelledCollection(std_train_X, train.labels, classes=train.classes_)
test = LabelledCollection(std_test_X, test.labels, classes=test.classes_)
return Dataset(training, test, dataset.vocabulary, dataset.name) return Dataset(training, test, dataset.vocabulary, dataset.name)