Building Learning Curves
If we want to test many different values for a single hyperparameter it can be difficult to easily view that in the form of a DataFrame. Previously you learned about a nice trick to analyze this. A graph called a 'learning curve' can nicely demonstrate the effect of increasing or decreasing a particular hyperparameter on the final result.
Instead of testing only a few values for the learning rate, you will test many to easily see the effect of this hyperparameter across a large range of values. A useful function from NumPy is np.linspace(start, end, num)
which allows you to create a number of values (num
) evenly spread within an interval (start
, end
) that you specify.
You will have available X_train
, X_test
, y_train
& y_test
datasets.
This exercise is part of the course
Hyperparameter Tuning in Python
Exercise instructions
- Create a list of 30 learning rates evenly spread between 0.01 and 2.
- Create a similar loop to last exercise but just save out accuracy scores to a list.
- Plot the learning rates against the accuracy score.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Set the learning rates & accuracies list
learn_rates = np.linspace(____, ____, num=____)
accuracies = []
# Create the for loop
for learn_rate in learn_rates:
# Create the model, predictions & save the accuracies as before
model = GradientBoostingClassifier(learning_rate=____)
predictions = model.fit(____, ____).predict(____)
accuracies.append(accuracy_score(y_test, ____))
# Plot results
plt.plot(____, ____)
plt.gca().set(xlabel='learning_rate', ylabel='Accuracy', title='Accuracy for different learning_rates')
plt.____