Sklearn StandardScaler scalable average is not zero

I have the following code

import pandas as pd
from sklearn.preprocessing import StandardScaler
import numpy as np

df.columns=['sepal_len', 'sepal_wid', 'petal_len', 'petal_wid', 'class']
df.dropna(how="all", inplace=True) # drops the empty line at file-end 

X = df.ix[:,0:4].values
y = df.ix[:,4].values

Next, I scale the data and get the average values:

X_std = StandardScaler().fit_transform(X)
mean_vec = np.mean(X_std, axis=0)

What I don't understand is that my conclusion is:

[ -4.73695157e-16  -6.63173220e-16   3.31586610e-16  -2.84217094e-16]

I understand how these values ​​can be anything other than 0. If I scale it, should it be zero 0?

Can someone explain to me what is going on here?

+6
source share
2 answers

In practice, these values ​​are so close to 0 that you can read them 0.

Scaler tries to set the average value to zero, but due to limitations with the numerical representation, he can only get the average value close to 0.

.

Machine Epsilon float 64 - 2.22e-16

+7
'[[-1.68171537e-01 -5.43628353e-01  5.81630904e-01 ... -2.84537246e-01
    2.30105715e+00  3.32291190e+00]]
' 

, , 0. ?

0

Source: https://habr.com/ru/post/1659744/


All Articles