Can anyone explain the math behind the scenes? why Python and R return me the different result? which one should I use for real-world business scenario?
original data
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 code:
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 normalized result
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
and R code
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 normalized result
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
thanks @Wen