Evaluating four categories
The confusion matrix is the most straightforward tool to look at the four categories of outcomes: true positives (TP), false positives (FP), true negatives (TN), and false negatives (FN). In this exercise, you will use a standard decision tree classifier DecisionTreeClassifier() from sklearn on the sample click data and calculate the breakdowns of outcomes by the four categories.
The pandas module is available as pd in your workspace and the sample DataFrame is loaded as df. The features are loaded in X and the target is loaded in y for use. Additionally, DecisionTreeClassifier from sklearn.tree is available.
Este ejercicio forma parte del curso
Predicting CTR with Machine Learning in Python
Instrucciones del ejercicio
- Obtain the training and testing splits for
Xandy. - Define a decision tree classifier and produce predictions
y_predby fitting the model. - Use the confusion matrix to get the counts for categories of each outcome, with a
1being a positive (click) and0being a negative (non-click). - For example: true negatives would be
[0,0]and true positives would be[1,1].
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Set up classifier using training data to predict test data
X_train, X_test, y_train, y_test = ____(
X, y, test_size = .2, random_state = 0)
clf = ____
y_pred = clf.____(X_train, y_train).____(X_test)
# Define confusion matrix and four categories
conf_matrix = ____(y_test, y_pred)
tn = conf_matrix[____][____]
fp = conf_matrix[____][____]
fn = conf_matrix[____][____]
tp = conf_matrix[____][____]
print("TN: %s, FP: %s, FN: %s, TP: %s" %(tn, fp, fn, tp))