Check our results
Once we have an optimized model, we want to check how it is performing in more detail. We already saw the R\(^2\) score, but it can be helpful to see the predictions plotted vs actual values. We can use the .predict() method of our decision tree model to get predictions on the train and test sets.
Ideally, we want to see diagonal lines from the lower left to the upper right. However, due to the simplicity of decisions trees, our model is not going to do well on the test set. But it will do well on the train set.
Este ejercicio forma parte del curso
Machine Learning for Finance in Python
Instrucciones del ejercicio
- Create a
DecisionTreeRegressormodel calleddecision_treeusing 3 for themax_depthhyperparameter. - Make predictions on the train and test sets (
train_featuresandtest_features) with our decision tree model. - Scatter the train and test predictions vs the actual target values with
plt.scatter(), and set thelabelargument equal totestfor the test set.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Use the best max_depth of 3 from last exercise to fit a decision tree
decision_tree = ____
decision_tree.fit(train_features, train_targets)
# Predict values for train and test
train_predictions = decision_tree.predict(train_features)
test_predictions = ____
# Scatter the predictions vs actual values
plt.scatter(train_predictions, train_targets, label='train')
plt.scatter(____)
plt.show()