liveBook · Manning

Newton-raphson method

As explained in Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI

A Newton-Raphson update is an optimization step that uses first- and second-order derivatives to refine parameter values.

The Newton-Raphson method refines model predictions by combining the first derivative, or gradient, with the second derivative, or Hessian. In gradient boosting, this second-order information adjusts each update to the objective function’s curvature rather than relying on gradient size alone. section 5.4.2

For practical machine-learning work, the method provides several useful behaviors:

  • Larger curvature reduces the gradient’s effect, acting as a brake on the learning rate; smaller curvature accelerates it. section 5.4.2
  • A regularization term can stabilize the update and help prevent overfitting. section 5.4.2
  • XGBoost uses Newton Descent as one of its optimization techniques, alongside specialized feature-splitting and sparse-data handling. section 5.4

A Newton-style boosting update

A custom NewtonianGradientBoosting implementation calculates gradient and Hessian values, then fits a decision tree to -gradient / (hessian + reg_lambda). With reg_lambda set to 0.25, the denominator regularizes the second-order update. section 5.4.2

Listing 5.13 How XGBoost works
class NewtonianGradientBoosting(GradientBoosting):              #1
    """the Newton-Raphson method is used to update the predictions"""
    
    reg_lambda = 0.25                                           #2
    
    def hessian(self, y_true, y_pred):
        hessian = np.ones_like(y_true)                          #3
        return hessian
    
    def fit(self, X, y):
        self.init = self.logit(np.mean(y))
        y_pred = self.init * np.ones((X.shape[0],))
        
        for k in range(self.n_estimators):
            gradient = self.gradient(self.logit(y), y_pred)
            hessian = self.hessian(self.logit(y), y_pred)
            tree = DecisionTreeRegressor(**self.params)
            tree.fit(
                X, 
                -gradient / (
                    hessian + self.reg_lambda
                )
            )                                                   #4
            self.trees.append(tree)
            y_pred += self.learning_rate * tree.predict(X)
        
cls = NewtonianGradientBoosting(n_estimators=300,
                                learning_rate=0.1,
                                max_depth=4,
                                min_samples_leaf=3, 
                                random_state=0)                 #5
 
cls.fit(X, y)                                                   #6
preds = cls.predict(Xt)
score = accuracy_score(y_true=yt, y_pred=preds)
print(f"Accuracy: {score:0.5f}")                                #7

Inspect the implementation showing initialization, gradient and Hessian calculation, regularization, and tree fitting. section 5.4.2

How Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI covers it

How deep it goes
Explains gradients, Hessians, curvature, adaptive learning rates, regularization, and a custom implementation, but avoids a full derivation.
Examples
Demonstrates a NewtonianGradientBoosting class that fits decision trees using gradient, Hessian, and regularization values.
What it assumes
Builds on gradient boosting and first derivatives, while explaining second derivatives through curvature and learning-rate intuition.
What you can do after
Apply it via XGBoost or implement a Newton-style boosting update with Hessian-based regularization.
How it connects
Connects Newton descent with gradient boosting, Hessian matrices, regularization, decision trees, and XGBoost.

Also explained in

Compare how 2 books explain newton-raphson method →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI. The section links point to the parts of the book it draws on.