Aan de slagGa gratis aan de slag

Visualize the results

We've fit our model with the custom loss function, and it's time to see how it is performing. We'll check the R\(^2\) values again with sklearn's r2_score() function, and we'll create a scatter plot of predictions versus actual values with plt.scatter(). This will yield some interesting results!

Deze oefening maakt deel uit van de cursus

Machine Learning for Finance in Python

Cursus bekijken

Oefeninstructies

  • Create predictions on the test set with .predict(), model_2, and scaled_test_features.
  • Evaluate the R\(^2\) score on the test set predictions using test_preds and test_targets.
  • Plot the test set targets vs actual values with plt.scatter(), and label it 'test'.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Evaluate R^2 scores
train_preds = model_2.predict(scaled_train_features)
test_preds = ____
print(r2_score(train_targets, train_preds))
print(____)

# Scatter the predictions vs actual -- this one is interesting!
plt.scatter(train_preds, train_targets, label='train')
plt.scatter(____)  # plot test set
plt.legend(); plt.show()
Code bewerken en uitvoeren