ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

Introduction to Predictive Analytics in Python

Ver curso

Instrucciones del ejercicio

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

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# 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])
Editar y ejecutar código