CommencerCommencer gratuitement

ROI on ad spend

The return on investment (ROI) for ad spend can be categorized using the four outcomes from a confusion matrix. This quantity is defined as the ratio between the total return and the total cost. If this quantity is greater than 1, it indicates the total return was greater than the total cost and vice versa. In this exercise, you will compute a sample ROI assuming a fixed r, the return on a click per number of impressions, and cost, the cost per number of impressions.

The pandas module is available as pd in your workspace and the sample DataFrame is loaded as df. The arrays y_test (target values of testing set) and y_pred (predicted target values) are available for use. Additionally, DecisionTreeClassifier from sklearn.tree is available.

Cet exercice fait partie du cours

Predicting CTR with Machine Learning in Python

Afficher le cours

Instructions

  • Compute the confusion matrix and get the four categories via flattening the matrix using .ravel().
  • Calculate the total return (using r) and total cost (using cost) by using quantities from the four categories.
  • Calculate the total ROI.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Compute confusion matrix and get four categories
conf_matrix = ____(y_test, y_pred)
tn, fp, fn, tp = conf_matrix.____

# Calculate total return, total spent, and ROI
r = 0.2
cost = 0.05
total_return = ____ * r
total_cost = (____ + ____) * cost 
roi = ____ / ____
print("Total return: %s, Total cost: %s, ROI: %s" %(
  total_return, total_cost, roi))
Modifier et exécuter le code