始める無料で始める

グループサイズをプロットする

predictor insight graph は予測に効く変数についての情報を示します。各変数は母集団を複数のグループに分けます。predictor insight graph では、各グループの平均ターゲット発生率を示す折れ線と、グループのサイズを示す棒が描かれます。 この演習では、predictor insight graph テーブルを入力として、predictor insight graph をプロットする関数の書き方と使い方を学びます。

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

Pythonで学ぶ予測分析入門

コースを見る

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# The function to plot a predictor insight graph
def plot_pig(pig_table, variable):
    
    # Plot formatting
    plt.ylabel("Size", rotation=0, rotation_mode="anchor", ha="right")
    
    # Plot the bars with sizes 
    pig_table["____"].plot(kind="bar", width=0.5, color="lightgray", edgecolor="none") 
    
    # Plot the incidence line on secondary axis
    pig_table["____"].plot(secondary_y=True)
    
    # Plot formatting
    plt.xticks(np.arange(len(pig_table)), pig_table[variable])
    plt.xlim([-0.5, len(pig_table) - 0.5])
    plt.ylabel("Incidence", rotation=0, rotation_mode="anchor", ha="left")
    
    # Show the graph
    plt.show()
コードを編集して実行