Model comparison warmup
In this exercise, you will run a basic comparison of the four categories of outcomes between MLPs and Random Forests using a confusion matrix. This is in preparation for an analysis of all the models we have covered. Doing this warm-up exercise will allow you to compare and contrast the implementation of these models and their evaluation for CTR prediction.
In the workspace, we have training and testing splits for X
and y
as X_train
, X_test
for X
and y_train
, y_test
for y
respectively. Remember, X
contains our engineered features with user, device, and site details whereas y
contains the target (whether the ad was clicked). X
has already been scaled using a StandardScaler()
. For future ad CTR prediction models, the setup will be analogous.
This exercise is part of the course
Predicting CTR with Machine Learning in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create the list of models in the order below
names = ['Random Forest', 'Multi-Layer Perceptron']
classifiers = [RandomForestClassifier(),
____(____ = (10, ),
____ = 40)]
# Produce a confusion matrix for all classifiers
for name, classifier in zip(names, classifiers):
print("Evaluating classifier: %s" %(name))
classifier.fit(____, ____)
y_pred = classifier.predict(____)
conf_matrix = confusion_matrix(____, ____)
print(conf_matrix)