1. Learn
  2. /
  3. Courses
  4. /
  5. Predicting CTR with Machine Learning in Python

Connected

Exercise

Model selection

Both regularization and cross validation are powerful tools in model selection. Regularization can help prevent overfitting and cross validation ensures that your models are being evaluated properly. In this exercise, you will use regularization and cross validation together and see whether or not models differ significantly. You will calculate the precision only, although the same exercise can easily be done for recall and other evaluation metrics as well.

X_train, y_train, X_test, y_test are available in your workspace. pandas as pd, numpy as np, and sklearn are also available in your workspace. Both precision_score() and recall_score() from sklearn.metrics are available as well as KFold() and cross_val_score() from sklearn.model_selection.

Instructions

100 XP
  • Set up a K-Fold cross validation with four splits using n_splits and assign it to k-fold.
  • Create a decision tree classifier.
  • Use k_fold to run cross validation and evaluate the precision and recall of your decision tree model for the given max_depth value.