Vẽ biểu đồ tỷ lệ xuất hiện
Yếu tố quan trọng nhất của predictor insight graph là các giá trị tỷ lệ xuất hiện (incidence). Với mỗi nhóm trong quần thể theo một biến nhất định, các giá trị incidence phản ánh phần trăm mục tiêu (target) trong nhóm đó. Trong bài tập này, bạn sẽ viết một hàm Python để vẽ các giá trị incidence của một biến, dựa trên bảng predictor insight graph đã cho.
Bài tập này là một phần của khóa học
Nhập môn Phân tích Dự đoán với Python
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
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()