Measure performance
Now that we've fit our neural net, let's check performance to see how well our model is predicting new values. There's not a built-in .score() method like with sklearn models, so we'll use the r2_score() function from sklearn.metrics. This calculates the R\(^2\) score given arguments (y_true, y_predicted). We'll also plot our predictions versus actual values again. This will yield some interesting results soon (once we implement our own custom loss function).
Este exercicio faz parte do curso
Machine Learning for Finance in Python
Instruções do exercicio
- Obtain predictions from
model_1on the scaled test set data (scaled_test_featuresandtest_targets). - Print the R\(^2\) score on the test set (
test_targetsandtest_preds). - Plot the
test_predsversustest_targetsin a scatter plot withplt.scatter().
exercicio interativo prático
Tente este exercicio completando este código de exemplo.
from sklearn.metrics import r2_score
# Calculate R^2 score
train_preds = model_1.predict(scaled_train_features)
test_preds = model_1.predict(____)
print(r2_score(train_targets, train_preds))
print(r2_score(____, ____))
# Plot predictions vs actual
plt.scatter(train_preds, train_targets, label='train')
plt.scatter(____)
plt.legend()
plt.show()