basictree py import numpy as np from sklearn datasets import make_friedman from sklearn model_selection import train_test_split def makedata ()n_points number of samples xy make_friedman n_samples =n_points n_features = noise = random_state = return train_test_split (xytest_size = random_state = the "mainmethod calls the makedata methoduses the training data to build regression treeand then predicts the responses of the test set and reports the mean squared-error loss def main ()x_train x_test y_train y_test makedata (maxdepth maximum tree depth create tree root at depth treeroot tnode ( x_train y_train build the regression tree with maximal depth equal to max_depth construct_subtree (treeroot maxdepth predict y_hat np zeros (lenx_test )for in range (lenx_test ))y_hat [ipredict x_test [ ]treeroot mse np mean(np power y_hat y_test , )print (basic treetree loss "msethe next step is to specify tree node as python class each node has number of attributesincluding the features and the response data ( and yand the depth at which the node is placed in the tree the root node has depth each node can calculate its contribution to the squared-error training loss ni= {xi rw }(yi gw (xi )) note that we have omitted the constant / term when training the treewhich simply scales the loss ( class tnode def __init__ (self depth xy)self depth depth self matrix of features self vector of response variables initialize optimal split parameters self none self xi none initialize children to be none self left none self right none initialize the regional predictor