StandardScaler role:
StandardScaler data set is normalized to do, he performed as a unit calculated on the basis that each feature
Calculation method:
(Original value - average value) / standard deviation
Code validation:
Call StandardScaler
import numpy as np
from sklearn.preprocessing import StandardScaler
np.random.seed(42)
samples = np.random.randn(10,1)
scaler = StandardScaler()
scaler.fit(samples)
Out:
StandardScaler(copy=True, with_mean=True, with_std=True)
Done manually
# 预测函数
def scale(series, x):
mean = np.mean(series)
std = np.std(series)
return (x-mean)/std
verification
scale(samples[:,0], np.array([[1],[2]]))
Out:
array([[0.80468598],
[2.26261185]])
scaler.transform(np.array([[1],[2]]))
Out:
array([[0.80468598],
[2.26261185]])
in conclusion
Manual method with the same result, which is verified StandardScaler algorithm, which is calculated as:
Dump failed to re-upload canceled dump failed to re-upload canceled