July 2019
Beginner to intermediate
298 pages
7h 20m
English
Scikit-learn also implements random forests for regression purposes in the RandomForestRegressor class. It is also highly parameterizable, with hyper-parameters concerning both the ensemble as a whole, as well as the individual trees. Here, we will generate an ensemble in order to model the diabetes regression dataset. The code follows the standard procedure of loading libraries and data, creating the ensemble and calling the fit and predict methods, along with calculating the MSE and R-squared values:
# --- SECTION 1 ---# Libraries and data loadingfrom copy import deepcopyfrom sklearn.datasets import load_diabetesfrom sklearn.ensemble import RandomForestRegressorfrom sklearn import metricsimport numpy as np ...
Read now
Unlock full access