标准化(Standardization)
归一化在把一列数据缩放到两个边界之间时很有用,但是如果其中任意一列受异常值影响过大,就很难将两列缩放后的数据进行比较。一个常用的解决方案是标准化:不再设置严格的上、下界,而是将数据以其均值为中心,并计算每个数据点相对于均值的标准差数量(即 z 分数)。
本练习是课程的一部分
Python 中的机器学习特征工程
练习说明
- 从
sklearn的preprocessing模块中导入StandardScaler。 - 将
StandardScaler()实例化为SS_scaler。 - 在
so_numeric_df的Age列上拟合StandardScaler。 - 使用刚刚拟合的缩放器转换同一列。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import StandardScaler
____
# Instantiate StandardScaler
SS_scaler = ____()
# Fit SS_scaler to the data
____.____(so_numeric_df[['Age']])
# Transform the data using the fitted scaler
so_numeric_df['Age_SS'] = ____.____(so_numeric_df[['Age']])
# Compare the origional and transformed column
print(so_numeric_df[['Age_SS', 'Age']].head())