การพล็อตค่า Incidence
องค์ประกอบที่สำคัญที่สุดของ predictor insight graph คือค่า incidence สำหรับแต่ละกลุ่มในประชากรที่แบ่งตามตัวแปรที่กำหนด ค่า incidence สะท้อนถึงเปอร์เซ็นต์ของ target ในกลุ่มนั้น ในแบบฝึกหัดนี้ จะได้เขียนฟังก์ชัน Python สำหรับพล็อตค่า incidence ของตัวแปร โดยใช้ตาราง predictor insight graph เป็นข้อมูลนำเข้า
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์เชิงพยากรณ์เบื้องต้นด้วย Python
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
import matplotlib.pyplot as plt
import numpy as np
# The function to plot a predictor insight graph.
def plot_incidence(pig_table,variable):
# Plot the incidence line
____["____"].plot()
# Formatting the predictor insight graph
plt.xticks(np.arange(len(pig_table)), pig_table[variable])
plt.xlim([-0.5, len(pig_table) - 0.5])
plt.ylim([0, max(pig_table["Incidence"] * 2)])
plt.ylabel("Incidence", rotation=0, rotation_mode="anchor", ha="right")
plt.xlabel(variable)
# Show the graph
plt.show()