self none def calculateloss (self)if(len(self )== )return return np sum(np power (self self mean (, )the function below implements the training (tree-buildingalgorithm def construct_subtree (node max_depth )if(node depth =max_depth or len(node = )node node mean (elsejxi calculateoptimalsplit (nodenode node xi xi xt yt xf yf datasplit (node xnode yjxiif(len(yt> )node left tnode (node depth + ,xt ,ytconstruct_subtree (node left max_depth if(len(yf> )node right tnode (node depth + xf ,yfconstruct_subtree (node right max_depth return node this requires an implementation of the calculateoptimalsplit function to startwe implement function datasplit that splits the data according to ( { xdef datasplit ( , , ,xi)ids [:, ]<=xi xt [ids =true ,:xf [ids =false ,:yt [ids =trueyf [ids =false return xt yt xf yf the calculateoptimalsplit method runs through the possible splitting thresholds from the set { , and finds the optimal split def calculateoptimalsplit (node) node node best_var best_xi [ best_var best_split_val node calculateloss (mn shape for in range ( , )