ComeçarComece de graça

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.

Este exercício faz parte do curso

Predicting CTR with Machine Learning in Python

Ver curso

Instruções do exercício

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

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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))
Editar e executar o código