테스트 데이터 예측하기
학습이 완료된 로지스틱 모델 df_fitted가 준비되어 있어요. 이 모델을 위한 테스트 데이터가 담긴 데이터프레임 df_testset도 제공됩니다. 또한 변수 fields에는 ['prediction', 'label', 'endword', 'doc', 'probability'] 목록이 들어 있으며, 이는 출력할 예측 필드를 지정하는 데 사용해요.
이 연습은 강의의 일부입니다
Python에서 Spark SQL 입문
연습 안내
df_testset의 데이터에 모델을 적용하세요.- 예측이 레이블과 일치하지 않으면 "incorrect"를 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Apply the model to the test data
predictions = df_fitted.____(____).select(fields)
# Print incorrect if prediction does not match label
for x in predictions.take(8):
print()
if x.label != int(x.____):
print("INCORRECT ==> ")
for y in fields:
print(y,":", x[y])