Get startedGet started for free

See how the ensemble performed

Let's check performance of our ensembled model to see how it's doing. We should see roughly an average of the R\(^2\) scores, as well as a scatter plot that is a mix of our previous models' predictions. The bow-tie shape from the custom loss function model should still be a bit visible, but the edges near x=0 should be softer.

This exercise is part of the course

Machine Learning for Finance in Python

View Course

Exercise instructions

  • Evaluate the R\(^2\) scores on the train and test sets. Use the sklearn r2_score() function (already imported for you) with train_targets and train_preds from the previous exercise.
  • Plot the train and test predictions versus the actual values with plt.scatter().

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

from sklearn.metrics import r2_score

# Evaluate the R^2 scores
print(r2_score(____, ____))
print(r2_score(test_targets, test_preds))

# Scatter the predictions vs actual -- this one is interesting!
plt.scatter(____, ____, ____)
plt.scatter(test_preds, test_targets, label='test')
plt.legend(); plt.show()
Edit and Run Code