rasbt / mlxtend

A library of extension and helper modules for Python's data analysis and machine learning libraries.
https://rasbt.github.io/mlxtend/
Other
4.82k stars 853 forks source link

Standardize does not handle constant columns #1058

Open Markopolo141 opened 11 months ago

Markopolo141 commented 11 months ago

Describe the bug

calling standardize() does not properly handle columns which are constant

Steps/Code to Reproduce

import numpy as np
Z = np.array([[0,1,2,5],[1,2,3,5],[3,1,2,5]])
print(standardize(Z))

outputs a column of -5.

Suggested Fix

Insert below line 130 in scaling.py

parameters["avgs"][c] = 0.0

Expected Results

should have column of zeros instead of -5.

Actual Results

has a column of -5s when it should have column of zero

Versions

MLxtend 0.22.0 Linux-5.19.0-46-generic-x86_64-with-glibc2.35 Python 3.9.17 (main, Jun 6 2023, 20:11:21) [GCC 11.3.0] Scikit-learn 1.2.2 NumPy 1.23.5 SciPy 1.10.0