Gom tất cả các bảng predictor insight graph
Trong bài tập trước, bạn đã xây dựng một hàm để tính bảng predictor insight graph cho một biến như sau:
pig_table = create_pig_table(basetable, "target","variable")
Nếu bạn muốn tính bảng predictor insight graph cho nhiều biến cùng lúc, một cách hay là lưu chúng trong một dictionary. Bạn có thể tạo một dictionary mới bằng dictionary = {}, thêm phần tử với một khóa bằng dictionary["key"] = value và truy xuất phần tử bằng khóa print(dictionary["key"]).
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
- Tạo một dictionary rỗng
pig_tables. - Với mỗi biến, tạo một bảng predictor insight graph.
- Với mỗi biến, thêm bảng predictor insight graph này vào dictionary, dùng tên biến làm khóa.
- In ra bảng predictor insight graph của
disc_time_since_last_gift.
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.
# Create the list of variables for our predictor insight graph tables
variables = ["income","gender","disc_mean_gift","disc_time_since_last_gift"]
# Create an empty dictionary
pig_tables = ____
# Loop through the variables
for variable in variables:
# Create a predictor insight graph table
pig_table = ____(basetable, ____, ____)
# Add the table to the dictionary
pig_tables[____] = ____
# Print the predictor insight graph table of the variable "disc_time_since_last_gift"
print(pig_tables["____"])