Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preprocessing with L-inf Normalizer of all-negative elements vector returns all-positive elements vector #16632

maurapintor opened this issue Mar 4, 2020 · 1 comment · Fixed by #16633


Copy link

maurapintor commented Mar 4, 2020

Describe the bug

L inf normalizer should take the maximum of the absolute value before dividing the array.

Steps/Code to Reproduce

from sklearn.preprocessing import Normalizer
import numpy as np

a = np.array([[1]])

normalizer = Normalizer(norm='max')

b = normalizer.fit_transform(a)
c = normalizer.fit_transform(-a)

# they should be different
print(b, c)

Expected Results

The normalized version of a vector with only negative elements should remain negative. It should take maximum absolute value, which is positive, hence remains negative.

Actual Results

The normalization applied to a positive-only vector and to a negative-only vector returns the same results.


Python dependencies:
pip: 19.0.3
setuptools: 40.8.0
sklearn: 0.22.2.post1
numpy: 1.18.1
scipy: 1.4.1
Cython: None
pandas: None
matplotlib: 3.1.3
joblib: 0.14.1

Possible fix

Take the absolute value before taking the max in this line.

Thanks to @freezebat for identifying the problem

@maurapintor maurapintor added the Bug: triage Reported bugs that are not confirmed label Mar 4, 2020
@rth rth added Bug and removed Bug: triage Reported bugs that are not confirmed labels Mar 4, 2020
Copy link

rth commented Mar 4, 2020

Thanks for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging a pull request may close this issue.

2 participants