Making predictions
Once your model is ready, you can use it to make predictions for a campaign. It is important to always use the latest information to make predictions.
In this exercise you will, given a fitted logistic regression model, learn how to make predictions for a new, updated basetable.
The logistic regression model that you built in the previous exercises has been added and fitted for you in logreg.
Bu egzersiz
Introduction to Predictive Analytics in Python
kursunun bir parçasıdırEgzersiz talimatları
- The latest data is in
current_data. Create a data framenew_datathat selects the relevant columns fromcurrent_data. - Assign to
predictionsthe predictions for the observations innew_data.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# 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])