开始使用免费开始使用

测试 QuantileTransformer

标准化与 z 分数有相同的隐患。二者都在计算中使用均值和标准差,因此对极端值非常敏感。

为避免这个问题,您应使用基于分位数的 QuantileTransformer。分布的分位数不受异常值幅度的影响,因此更稳健。

当数据近似正态分布时(可用直方图检查),应使用 StandardScaler。对于其他分布,QuantileTransformer 往往是更好的选择。

本练习将使用已加载的 females 数据集。matplotlib.pyplot 已按其常用别名 plt 加载。

本练习是课程的一部分

Python 中的异常检测

查看课程

练习说明

  • 实例化一个将特征变换为正态分布的 QuantileTransformer(),并将其赋给 qt
  • 拟合并变换特征数组 X,同时保留列名。
  • 绘制 palmlength 列的直方图。

交互式实操练习

通过完成这段示例代码来试试这个练习。

from sklearn.preprocessing import QuantileTransformer

# Instantiate an instance that casts to normal
qt = ____

# Fit and transform the feature array
X.____ = ____

# Plot a histogram of palm length
plt.____(____, color='red')

plt.xlabel("Palm length")
plt.show()
编辑并运行代码