모든 predictor insight graph 테이블 묶기
이전 연습 문제에서, 특정 변수에 대한 predictor insight graph 테이블을 다음과 같이 계산하는 함수를 만들었어요:
pig_table = create_pig_table(basetable, "target","variable")
여러 변수를 한꺼번에 계산하려면, 딕셔너리에 저장하는 것이 좋아요. dictionary = {}로 새 딕셔너리를 만들고, dictionary["key"] = value처럼 키와 함께 요소를 추가한 다음, print(dictionary["key"])로 키를 사용해 요소를 가져올 수 있어요.
이 연습은 강의의 일부입니다
Python으로 배우는 예측 분석 입문
연습 안내
- 빈 딕셔너리
pig_tables를 만드세요. - 각 변수에 대해 predictor insight graph 테이블을 만드세요.
- 각 변수에 대해, 변수 이름을 키로 하여 이 predictor insight graph 테이블을 딕셔너리에 추가하세요.
disc_time_since_last_gift의 predictor insight graph 테이블을 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# 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["____"])