始める無料で始める

数値列とカテゴリ列を分ける

前の演習でデータセットの特徴を確認し、データ前処理の準備ができました。ここでは、telco_raw DataFrame から、ユニーク値の数に基づくしきい値を用いてカテゴリ変数と数値変数を分けます。pandas モジュールは pd として読み込まれています。

テレコムの解約データセット telco_rawpandas の DataFrame として読み込まれています。まずはコンソールで中身を確認して慣れておきましょう。

この演習はコースの一部です

Pythonで学ぶマーケティングのための機械学習

コースを見る

演習の手順

  • customerIDChurn の列名を保存します。
  • ユニーク値が 5 未満の列名を categorical に代入します。
  • リストから target を削除します。
  • custidtargetcategorical に含まれないすべての列名を 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]
コードを編集して実行