開始使用免費開始

進行預測

模型建立完成後,你可以用它來對某個行銷活動進行預測。要記得,進行預測時務必使用最新的資訊。

在這個練習中,你會在已擬合好的邏輯斯迴歸模型下,學習如何對一個新的、已更新的 base table 進行預測。

你在前面練習建立的邏輯斯迴歸模型已幫你加入並擬合為 logreg

本練習屬於課程

Python 預測分析入門

檢視課程

練習說明

  • 最新資料在 current_data。建立一個資料框 new_data,從 current_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])
編輯並執行程式碼