July 2019
Beginner to intermediate
298 pages
7h 20m
English
We can easily parallelize our bagging implementation using from concurrent.futures import ProcessPoolExecutor. This executor allows the user to spawn a number of tasks to be executed and executes them in parallel processes. It only needs to be passed a target function and its parameters. In our example, we only need to create functions out of code sections (sections 2 and 3):
def create_learner(train_x, train_y): # We sample indices in order to access features and targets bootstrap_sample_indices = np.random.randint(0, train_size, size=train_size) bootstrap_x = train_x[bootstrap_sample_indices] bootstrap_y = train_y[bootstrap_sample_indices] dtree = DecisionTreeClassifier() dtree.fit(bootstrap_x, bootstrap_y) ...
Read now
Unlock full access