选择相关特征
在本练习中,您将找出 volunteer 数据集中的冗余列,并对数据集进行特征选择,返回只包含相关特征的 DataFrame。
例如,若您在控制台中探索 volunteer 数据集,会看到 3 个与位置相关的特征:locality、region 和 postalcode。它们包含相关信息,因此只保留其中 1 个特征更合理。
请在控制台中花些时间检查 volunteer 的各个特征,并尝试识别哪些是冗余特征。
本练习是课程的一部分
Python 中的机器学习预处理
练习说明
- 创建冗余列名列表,并将其存入变量
to_drop:- 在所有与位置相关的特征中,只保留
postalcode。 - 经特征工程处理过的特征同样视为冗余。
- 在所有与位置相关的特征中,只保留
- 从数据集中删除
to_drop列表中的列。 - 打印
volunteer_subset的.head(),查看已选择的列。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create a list of redundant column names to drop
to_drop = ["____", "____", "____", "____", "____"]
# Drop those columns from the dataset
volunteer_subset = ____.____(____, ____)
# Print out the head of volunteer_subset
print(____)