数値列とカテゴリ列を分ける
前の演習でデータセットの特徴を確認し、データ前処理の準備ができました。ここでは、telco_raw DataFrame から、ユニーク値の数に基づくしきい値を用いてカテゴリ変数と数値変数を分けます。pandas モジュールは pd として読み込まれています。
テレコムの解約データセット telco_raw は pandas の DataFrame として読み込まれています。まずはコンソールで中身を確認して慣れておきましょう。
この演習はコースの一部です
Pythonで学ぶマーケティングのための機械学習
演習の手順
customerIDとChurnの列名を保存します。- ユニーク値が 5 未満の列名を
categoricalに代入します。 - リストから
targetを削除します。 custid、target、categoricalに含まれないすべての列名をnumericalに代入します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Store customerID and Churn column names
custid = ['___']
target = ['___']
# Store categorical column names
categorical = telco_raw.___()[telco_raw.nunique() < ___].keys().tolist()
# Remove target from the list of categorical variables
categorical.remove(___[0])
# Store numerical column names
numerical = [x for x in telco_raw.___ if x not in custid + ___ + categorical]