舞台裏の数学を説明できる人はいますか? Python と R が異なる結果を返すのはなぜですか? 実際のビジネス シナリオではどちらを使用する必要がありますか?
元データ
id cost sales item
1 300 50 pen
2 3 88 wf
3 1 70 gher
4 5 80 dger
5 2 999 ww
Python コード:
import pandas as pd
from sklearn.preprocessing import StandardScaler
df = pd.read_csv('Scale.csv')
df[['cost', 'sales']] = StandardScaler().fit_transform(df[['cost', 'sales']])
df
Python 正規化結果
id cost sales item
0 1 1.999876 -0.559003 pen
1 2 -0.497867 -0.456582 wf
2 3 -0.514686 -0.505097 gher
3 4 -0.481047 -0.478144 dger
4 5 -0.506276 1.998826 ww
とRコード
library(readr)
library(dplyr)
df <- read_csv("C:/Users/Ho/Desktop/Scale.csv")
df <- df %>% mutate_each_(funs(scale(.) %>% as.vector),
vars=c("cost","sales"))
R正規化結果
id cost sales item
1 1 1.7887437 -0.4999873 pen
2 2 -0.4453054 -0.4083792 wf
3 3 -0.4603495 -0.4517725 gher
4 4 -0.4302613 -0.4276651 dger
5 5 -0.4528275 1.7878041 ww
ありがとう@ウェン