LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Introduction to Predictive Analytics in Python

Kurs anzeigen

Anleitung zur Übung

  • The latest data is in current_data. Create a data frame new_data that selects the relevant columns from current_data.
  • Assign to predictions the predictions for the observations in new_data.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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])
Code bearbeiten und ausführen