開始使用免費開始

選取重要特徵

在這個練習中,你需要只選擇會用在最終模型中的重要特徵。請記得,相對重要性已經儲存在名為 relative_importances 的 DataFrame 中的 importance 欄位。

本練習屬於課程

HR 分析:用 Python 預測員工流失

檢視課程

練習說明

  • 只選取 importance 大於 1% 的特徵。
  • 由這些特徵建立一個清單並將其印出(此步驟已為你完成)。
  • 使用儲存在 selected_list 的索引,將 features_trainfeatures_test 轉換為只包含重要性高於 1% 的特徵。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# select only features with relative importance higher than 1%
selected_features = relative_importances[relative_importances.____>0.01]

# create a list from those features: done
selected_list = selected_features.index

# transform both features_train and features_test components to include only selected features
features_train_selected = features_train[selected_list]
features_test_selected = ____[____]
編輯並執行程式碼