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.
Diese Übung ist Teil des Kurses
Predicting CTR with Machine Learning in Python
Anleitung zur Übung
- Define both
Xandyto be the features and target respectively based on theclickcolumn. - 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.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# 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))