4.1. Exercises

Feature Splitting

Parameter or Hyperparameter

For the following statements, state if it corresponds to a Parameter or Hyperparameter.

Playing with Hyperparameters

Instructions:
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.

When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.

Make sure you remove the hash (#) symbol in the coding portions of this question. We have commented them so that the line won’t execute and you can test your code after each step.

Let’s build a decision tree classifier using DecisionTreeClassifier() but this time, let’s set some different hyperparameters.

Tasks:

  • Build a decision tree classifier and make sure to set the argument random_state to 1.
  • Set the max_depth of the tree to 8 and the min_samples_split to 4.
  • Save the model in an object named hyper_tree.
  • Fit your model on the objects X and y.
  • Save the accuracy of the model rounded to 2 decimal places in a variable named tree_score and display it.
Hint 1
  • Are using DecisionTreeClassifier(max_depth=8, min_samples_split=4, random_state=1)?
  • Are you using the model named hyper_tree?
  • Are you calling .fit(X,y) on your model?
  • Are you using .score(X,y) and rounding to 2 decimal places by using round()?
Fully worked solution: