Build Grid Search functions
In data science it is a great idea to try building algorithms, models and processes 'from scratch' so you can really understand what is happening at a deeper level. Of course there are great packages and libraries for this work (and we will get to that very soon!) but building from scratch will give you a great edge in your data science work.
In this exercise, you will create a function to take in 2 hyperparameters, build models and return results. You will use this function in a future exercise.
You will have available the X_train
, X_test
, y_train
and y_test
datasets available.
This exercise is part of the course
Hyperparameter Tuning in Python
Exercise instructions
- Build a function that takes two parameters called
learning_rate
andmax_depth
for the learning rate and maximum depth. - Add capability in the function to build a GBM model and fit it to the data with the input hyperparameters.
- Have the function return the results of that model and the chosen hyperparameters (
learning_rate
andmax_depth
).
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create the function
def gbm_grid_search(____, ____):
# Create the model
model = GradientBoostingClassifier(____=___, ____=____)
# Use the model to make predictions
predictions = model.fit(____, ____).predict(____)
# Return the hyperparameters and score
return([____, ____, accuracy_score(____, ____)])