Skip to content

Commit

Permalink
CLN Move gradient and hessian closer to for loop in hist GBDT (#15686)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjpfan authored and NicolasHug committed Nov 20, 2019
1 parent ccac637 commit 1c546cd
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py
Expand Up @@ -191,13 +191,6 @@ def fit(self, X, y):
)
raw_predictions += self._baseline_prediction

# initialize gradients and hessians (empty arrays).
# shape = (n_trees_per_iteration, n_samples).
gradients, hessians = self.loss_.init_gradients_and_hessians(
n_samples=n_samples,
prediction_dim=self.n_trees_per_iteration_
)

# predictors is a matrix (list of lists) of TreePredictor objects
# with shape (n_iter_, n_trees_per_iteration)
self._predictors = predictors = []
Expand Down Expand Up @@ -278,17 +271,18 @@ def fit(self, X, y):
X_binned_small_train, y_small_train = self._get_small_trainset(
X_binned_train, y_train, self._random_seed)

# Initialize the gradients and hessians
gradients, hessians = self.loss_.init_gradients_and_hessians(
n_samples=n_samples,
prediction_dim=self.n_trees_per_iteration_
)

# Get the predictors from the previous fit
predictors = self._predictors

begin_at_stage = self.n_iter_

# initialize gradients and hessians (empty arrays).
# shape = (n_trees_per_iteration, n_samples).
gradients, hessians = self.loss_.init_gradients_and_hessians(
n_samples=n_samples,
prediction_dim=self.n_trees_per_iteration_
)

for iteration in range(begin_at_stage, self.max_iter):

if self.verbose:
Expand Down

0 comments on commit 1c546cd

Please sign in to comment.