การพล็อตขนาดของกลุ่ม
กราฟ predictor insight จะแสดงข้อมูลเกี่ยวกับตัวแปรที่ใช้ในการพยากรณ์ โดยแต่ละตัวแปรจะแบ่งประชากรออกเป็นหลายกลุ่ม กราฟนี้ประกอบด้วยเส้นที่แสดงค่าเฉลี่ย target incidence ของแต่ละกลุ่ม และแท่งกราฟที่แสดงขนาดของแต่ละกลุ่ม ในแบบฝึกหัดนี้ คุณจะได้เรียนรู้วิธีเขียนและใช้งานฟังก์ชันสำหรับพล็อต 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()