Session Ready
Exercise

Make predictions with a random forest

In order to fit a machine learning model to predict ideal portfolios, we need to create train and test sets for evaluating performance. We will do this as we did in previous chapters, where we take our features and targets arrays, and split them based on a train_size we set. Often the train size may be around 70-90% of our data.

We then fit our model (a random forest in this case) to the training data, and evaluate the R\(^2\) scores on train and test using .score() from our model. In this case, the hyperparameters have been set for you, but usually you'd want to do a search with ParameterGrid like we did in previous chapters.

Instructions
100 XP
  • Set the train_size to be 85% of the full training set data using the .shape property of features.
  • Create train and test targets from targets using Python indexing.
  • Fit the random forest model to the train_features and train_targets.