예측 만들기
모델을 준비했으면 캠페인에 대한 예측에 활용할 수 있어요. 예측을 할 때는 항상 최신 정보를 사용하는 것이 중요합니다.
이 연습 문제에서는 적합된 로지스틱 회귀 모델을 바탕으로, 새로 업데이트된 베이스테이블에 대해 예측을 만드는 방법을 배웁니다.
이전에 구축한 로지스틱 회귀 모델은 logreg에 추가되어 이미 적합되어 있습니다.
이 연습은 강의의 일부입니다
Python으로 배우는 예측 분석 입문
연습 안내
- 최신 데이터는
current_data에 있습니다.current_data에서 관련 열만 선택해 데이터 프레임new_data를 만드세요. new_data의 관측치에 대한 예측 값을predictions에 할당하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Fit a logistic regression model
from sklearn import linear_model
X = basetable[["age","gender_F","time_since_last_gift"]]
y = basetable[["target"]]
logreg = linear_model.LogisticRegression()
logreg.fit(X, y)
# Create a DataFrame new_data from current_data that has only the relevant predictors
new_data = ____[[____, ____, ____]]
# Make a prediction for each observation in new_data and assign it to predictions
predictions = ____.____(____)
print(predictions[0:5])