1. Learn
  2. /
  3. Courses
  4. /
  5. Predicting CTR with Machine Learning in Python

Exercise

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.

Instructions

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