分離目標與特徵
為了進行預測(此處是預測員工是否會離職),你需要將資料集分成兩個部分:
- 需要被預測的「相依變數」或「目標(target)」
- 用來做預測的「自變數」或「特徵(features)」
你的任務是分開 target 和 features。此處的 target 是員工離職(churn),而 features 則包含其餘所有欄位。
提醒:這個資料集已經先將類別變數做過編碼,並且建立了虛擬變數(dummy variables)。
pandas 已替你匯入為 pd。
本練習屬於課程
HR 分析:用 Python 預測員工流失
練習說明
- 設定 target 與 features:
- 選取相依變數欄位(
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)