Get startedGet started for free

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.

This exercise is part of the course

Introduction to Predictive Analytics in Python

View Course

Exercise instructions

  • 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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])
Edit and Run Code