8000 fix inplace/mask copy operation · scikit-learn/scikit-learn@810c637 · GitHub
[go: up one dir, main page]

Skip to content

Commit 810c637

Browse files
committed
fix inplace/mask copy operation
1 parent ddafd73 commit 810c637

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

sklearn/ensemble/weight_boosting.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,19 +1035,20 @@ def _boost(self, iboost, X, y, sample_weight, random_state):
10351035

10361036
error_vect = np.abs(y_predict - y)
10371037
sample_mask = sample_weight > 0
1038-
error_max = error_vect[sample_mask].max()
1038+
masked_sample_weight = sample_weight[sample_mask]
1039+
masked_error_vector = error_vect[sample_mask]
10391040

1041+
error_max = masked_error_vector.max()
10401042
if error_max != 0:
1041-
error_vect /= error_max
1043+
masked_error_vector /= error_max
10421044

10431045
if self.loss == 'square':
1044-
error_vect **= 2
1046+
masked_error_vector **= 2
10451047
elif self.loss == 'exponential':
1046-
error_vect = 1. - np.exp(- error_vect)
1048+
masked_error_vector = 1. - np.exp(-masked_error_vector)
10471049

10481050
# Calculate the average loss
1049-
estimator_error = (sample_weight[sample_mask] *
1050-
error_vect[sample_mask]).sum()
1051+
estimator_error = (masked_sample_weight * masked_error_vector).sum()
10511052

10521053
if estimator_error <= 0:
10531054
# Stop if fit is perfect
@@ -1066,8 +1067,8 @@ def _boost(self, iboost, X, y, sample_weight, random_state):
10661067

10671068
if not iboost == self.n_estimators - 1:
10681069
sample_weight[sample_mask] *= np.power(
1069-
beta,
1070-
(1. - error_vect[sample_mask]) * self.learning_rate)
1070+
beta, (1. - masked_error_vector) * self.learning_rate
1071+
)
10711072

10721073
return sample_weight, estimator_weight, estimator_error
10731074

0 commit comments

Comments
 (0)
0