# Standardscaler() not standardscaling?

I have following pipeline:

estimators = []
estimators.append(('standardize', StandardScaler()))
prepare_data = Pipeline(estimators)


Originally, the data looks like

After applying the estimator/StandardScaler()

X_train = prepare_data.fit_transform(X_train_raw)


Why are the values mostly/always negative now?

When I have a look at another variable in X_train it looks as it should (I guess):

Before

after

You got outliers. Standard scaler scales each attribute independently to center at zero and unit variance. Either deal with your outliers or use some more robust scaler. Try instead to plot each attribute with separate box plot.

• I think I understood it at least partially :) Outliers are the reason why it is far off from +1/-1, right? But shouldn't it be centered, anyways?
– Ben
Nov 22, 2019 at 12:45
• What exactly your plots represent? Mean for each attribute? Nov 22, 2019 at 12:48
• @Ben You should check what is the least negative value of your variable. Mean is not robust to outliers, that is for sure, or you can check with histogram, as piotr says box plot helps as well. Nov 22, 2019 at 12:56
• @PiotrRarus It is current and gas concentration.
– Ben
Nov 25, 2019 at 6:16
• @Ben, if you want to understand what's going on you need to get your hands dirty: do fit and store the obtained scaler. Only then call transform on that scaler. Inspect the attributes of the scaler .mean_ and .scale_ (std of x). Then go and visually check some of the scaled values. I suspect most are actually positive but small so we barely notice them on the plot, which then looks bias due to those extreme low peaks -not all are outliers I'd say. However, the values might be correct. Remember, the scaled values are $Z=\frac{x-\bar{x}}{S_x}$ You must have some positive values if done right.
– MASL
Jan 3, 2020 at 6:17