how to check if two fitted standard scalers are same python sklearn

Viewed 131

sklearn version = 0.24.2

While preprocessing daily data in week worth total.

I am fitting a standard scaler using each day's data distribution. I want to check if standard scaler fitted on 20210501 is same as 20210502. Instead of looking at the data itself(huge dataset) is there a way to compare two fitted scaler?

Reason for doing this is because I need to save fitted scaler so I can scale new data when it enters my ML serving API.

Thanks!

1 Answers

Yes, there are 3 relevant attributes of StandardScaler: scale_, mean_, var_

All of them are a numpy array with shape (n_features,). So, you can do

if np.allclose(scaler1.scale_==scaler2.scale_) 
   and np.allclose(scaler1.mean_==scaler2.mean_) 
   and np.allclose(scaler1.var_==scaler2.var_):
print("scalers are same")

Note that the attribute sizes are dependent on number of features. See this link https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html

Related