进行预测
模型准备好后,您就可以用它为一次营销活动进行预测。进行预测时务必使用最新信息。
在本练习中,给定一个已拟合的逻辑回归模型,您将学习如何为一个更新后的基表进行预测。
您在前面练习中构建的逻辑回归模型已添加并拟合为 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])