Implement gradient tree boosting for several losses: each round fits a regression tree to the pseudo-residuals (the negative gradient) and then re-solves each leaf's value for the actual loss.
gbm_fit(X, y, loss, M, nu, max_depth, delta=1.0) with loss one of:
"squared" : start ; residual ; leaf value = mean of in the leaf."absolute" : start ; residual (with ); leaf value = median of in the leaf."huber" with threshold : start ; residual if else , with ; leaf value = over the leaf, where is the leaf median of ."logloss" for with the log-odds and : start ; residual ; leaf value = over the leaf (one Newton step).Each round: compute at the current , grow a tree on , set every leaf's value by the rule above using the samples in that leaf, then .
Regression tree rules (so results are deterministic): grow depth-first from a root at depth 0. A node is split only if its depth is below max_depth, it has at least 2 samples, and some split strictly lowers the sum of squared errors (SSE) of the fitted target around the node mean by more than . Candidate splits are, for every feature in increasing order, the midpoints between consecutive distinct sorted values of that feature within the node, in increasing order; a sample goes left if x[feature] <= threshold. Choose the split with the smallest total child SSE, keeping the first one found on ties (lowest feature, then lowest threshold).
Return (model, losses) where losses is the mean training loss after each round (for log loss, the mean binary cross-entropy; for Huber, if else ). Implement gbm_predict(model, X) returning the raw score (log-odds for log loss).