Gradient boosting extends to classes by keeping one score function per class, , combined by a softmax . The pseudo-residual for class is , and each round fits separate regression trees.
Implement multiclass_gbm_fit(X, y, C, M, nu, max_depth) for integer labels , starting from for all classes. Each round:
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) with losses the mean training multiclass log loss after each round. Implement multiclass_gbm_predict_proba(model, X) returning the (n, C) matrix of softmax probabilities.