A first CTR model
In this exercise, you will build a first CTR model on the Avazu dataset using a decision tree and evaluate the accuracy of the model using accuracy_score()
from sklearn
. Additionally, you will use train_test_split()
from sklearn
to split training and testing data instead of manually defining a split point as before.
In your workspace, sample data in DataFrame form is loaded as df
along with sklearn
and pandas
as pd
.
We will do a basic training and testing split and evaluate our results using accuracy.
This exercise is part of the course
Predicting CTR with Machine Learning in Python
Exercise instructions
- Define both
X
andy
to be the features and target respectively based on theclick
column. - Split the data into training and testing sets using
train_test_split(X, y)
. - Create a decision tree classifier.
- Create predictions using the classifier and evaluate the accuracy of its predictions.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define X and y
X = df.____[:, ~df.columns.____(['click'])]
y = df.click
# Define training and testing
X_train, X_test, y_train, y_test = \
____(____, _____, test_size = .2, random_state = 0)
# Create decision tree classifier
clf = ____()
# Train classifier - predict label and evaluate accuracy
y_pred = clf.fit(____, _____).____(X_test)
print(____(y_test, y_pred))