开始使用免费开始使用

拆分目标与特征

为了进行预测(本例中是预测员工是否会离职),需要将数据集拆分为两个部分:

  • 需要被预测的因变量目标(target)
  • 用来进行预测的自变量特征(features)

您的任务是将 targetfeatures 分离。此处的目标是员工流失(离职)churn,而特征包含其余所有内容。

提醒:数据集已经过预处理,包括对分类变量进行编码并生成哑变量。

pandas 已为您导入为 pd

本练习是课程的一部分

HR Analytics:用 Python 预测员工流失

查看课程

练习说明

  • 设置目标和特征:
    • 选择因变量列(churn)并将其设为 target
    • 使用 .drop() 删除列 churn,其余列作为 features

交互式实操练习

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

# Set the target and features

# Choose the dependent variable column (churn) and set it as target
target = data.____

# Drop column churn and set everything else as features
features = data.____("____",axis=1)
编辑并运行代码