すべての予測因子インサイトグラフのテーブルをまとめる
前の演習では、次のように指定した変数の予測因子インサイトグラフのテーブルを計算する関数を作成しました。
pig_table = create_pig_table(basetable, "target","variable")
複数の変数について一度に予測因子インサイトグラフのテーブルを計算したい場合は、辞書に保存しておくと便利です。新しい辞書は dictionary = {} で作成し、キー付きで要素を追加するには dictionary["key"] = value、キーで要素を取り出すには print(dictionary["key"]) を使います。
この演習はコースの一部です
Pythonで学ぶ予測分析入門
演習の手順
- 空の辞書
pig_tablesを作成します。 - 各変数について、予測因子インサイトグラフのテーブルを作成します。
- 各変数について、変数名をキーとして、この予測因子インサイトグラフのテーブルを辞書に追加します。
disc_time_since_last_giftの予測因子インサイトグラフのテーブルを出力します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Create the list of variables for our predictor insight graph tables
variables = ["income","gender","disc_mean_gift","disc_time_since_last_gift"]
# Create an empty dictionary
pig_tables = ____
# Loop through the variables
for variable in variables:
# Create a predictor insight graph table
pig_table = ____(basetable, ____, ____)
# Add the table to the dictionary
pig_tables[____] = ____
# Print the predictor insight graph table of the variable "disc_time_since_last_gift"
print(pig_tables["____"])