I do data normalization as:
X = ( X - X.mean(axis=0) )/X.std(axis=0)
But some features have 0 variance. It gives me Runtime error for ZeroDivision.
I know we can normalize using “StandardScalar” class. But how can I normalize data by myself if std=0 .
Data Normalization
You can normalize your data by just adding a const in a denominator just to over come ZeroDivision Error therefore the function you are using to normalize the data changes as follow:
X = ( X - X.mean(axis=0) )/(X.std + a)(axis=0) ; {where a is the const}
Over here you can choose a small value for a like 1e-4 or 1e-6 so the effect of the const overall is quite minimal and even when std=0 overall denominator is non zero thus helping you to overcome ZeroDivision Error
Hope this might helps
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.