Tổng hợp mọi thứ lại
Trong các bài trước, bạn đã định nghĩa hàm create_pig_table để, với một basetable và một predictor, tạo ra bảng predictor insight graph cho predictor đó:
pig_table = create_pig_table(basetable,target,variable)
Tiếp theo, bạn đã viết hàm plot_pig để vẽ biểu đồ predictor insight graph dựa trên bảng predictor insight graph này
plot_pig(pig_table, variable)
Thực tế, bạn thường muốn tạo nhiều predictor insight graph cùng lúc. Trong bài này, bạn sẽ học cách tự động hóa việc đó bằng vòng lặp for.
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
Hướng dẫn bài tập
- Với mỗi biến trong
variables, tạo một bảng predictor insight graph. Basetable đã được nạp trongbasetable. - Với mỗi biến trong
variables, vẽ predictor insight graph.
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.
# Variables you want to make predictor insight graph tables for
variables = ["income","gender","disc_mean_gift","disc_time_since_last_gift"]
# Loop through the variables
for variable in variables:
# Create the predictor insight graph table
pig_table = ____(____, "target", variable)
# Plot the predictor insight graph
____(____, variable)