开始使用免费开始使用

训练集与测试集的变换(II)

与在训练集和测试集上应用同一标准化器类似,如果您在训练集中移除了异常值,通常也需要在测试集中进行相同的处理。再次强调,您应确保仅使用"基于训练集计算得到的阈值"来从测试集中移除异常值。

与上一个练习类似,我们将 so_numeric_df DataFrame 拆分为训练集(so_train_numeric)和测试集(so_test_numeric)。

本练习是课程的一部分

Python 中的机器学习特征工程

查看课程

练习说明

  • 计算 ConvertedSalary 列的标准差和均值。
  • 在均值的上下各三个标准差处计算上界和下界。
  • 截取 so_test_numeric DataFrame,仅保留 ConvertedSalary 介于下界与上界之间的所有行。

交互式实操练习

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

train_std = so_train_numeric['ConvertedSalary'].____
train_mean = so_train_numeric['ConvertedSalary'].____

cut_off = train_std * 3
train_lower, train_upper = ____, train_mean + cut_off

# Trim the test DataFrame
trimmed_df = so_test_numeric[(so_test_numeric['ConvertedSalary'] < ____) \
                             & (so_test_numeric['ConvertedSalary'] > ____)]
编辑并运行代码