Pythonでのさまざまな標準化の例。
参考として、このウィキペディアの記事をご覧ください:https :
 //en.wikipedia.org/wiki/Unbiased_estimation_of_standard_deviation
データの例
import pandas as pd
df = pd.DataFrame({
               'A':[1,2,3],
               'B':[100,300,500],
               'C':list('abc')
             })
print(df)
   A    B  C
0  1  100  a
1  2  300  b
2  3  500  c
パンダを使用した正規化(公平な推定値を提供)
正規化するときは、単純に平均を差し引き、標準偏差で割ります。
df.iloc[:,0:-1] = df.iloc[:,0:-1].apply(lambda x: (x-x.mean())/ x.std(), axis=0)
print(df)
     A    B  C
0 -1.0 -1.0  a
1  0.0  0.0  b
2  1.0  1.0  c
sklearnを使用した正規化(偏った推定値を与える、パンダとは異なる)
同じことをsklearnすると、異なる出力が得られます!
import pandas as pd
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
df = pd.DataFrame({
               'A':[1,2,3],
               'B':[100,300,500],
               'C':list('abc')
             })
df.iloc[:,0:-1] = scaler.fit_transform(df.iloc[:,0:-1].to_numpy())
print(df)
          A         B  C
0 -1.224745 -1.224745  a
1  0.000000  0.000000  b
2  1.224745  1.224745  c
sklearnのバイアス推定は機械学習の能力を低下させますか?
番号。  
sklearn.preprocessing.scaleの公式ドキュメントには、バイアス推定器を使用しても機械学習アルゴリズムのパフォーマンスに影響を与える可能性は低く、安全に使用できると記載されています。
From official documentation:
We use a biased estimator for the standard deviation,
equivalent to numpy.std(x, ddof=0). 
Note that the choice of ddof is unlikely to affect model performance.
MinMaxスケーリングはどうですか?
MinMaxスケーリングには標準偏差の計算はありません。したがって、パンダとscikit-learnの両方で結果は同じです。
import pandas as pd
df = pd.DataFrame({
               'A':[1,2,3],
               'B':[100,300,500],
             })
(df - df.min()) / (df.max() - df.min())
     A    B
0  0.0  0.0
1  0.5  0.5
2  1.0  1.0
# Using sklearn
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler() 
arr_scaled = scaler.fit_transform(df) 
print(arr_scaled)
[[0.  0. ]
 [0.5 0.5]
 [1.  1. ]]
df_scaled = pd.DataFrame(arr_scaled, columns=df.columns,index=df.index)
print(df_scaled)
     A    B
0  0.0  0.0
1  0.5  0.5
2  1.0  1.0