@@ -207,7 +207,7 @@ def _fit_stage(
207
207
"""Fit another stage of ``_n_classes`` trees to the boosting model."""
208
208
209
209
assert sample_mask .dtype == bool
210
- loss = self .loss_
210
+ loss = self ._loss
211
211
original_y = y
212
212
213
213
# Need to pass a copy of raw_predictions to negative_gradient()
@@ -328,11 +328,11 @@ def _check_params(self):
328
328
loss_class = _gb_losses .LOSS_FUNCTIONS [self .loss ]
329
329
330
330
if is_classifier (self ):
331
- self .loss_ = loss_class (self .n_classes_ )
331
+ self ._loss = loss_class (self .n_classes_ )
332
332
elif self .loss in ("huber" , "quantile" ):
333
- self .loss_ = loss_class (self .alpha )
333
+ self ._loss = loss_class (self .alpha )
334
334
else :
335
- self .loss_ = loss_class ()
335
+ self ._loss = loss_class ()
336
336
337
337
check_scalar (
338
338
self .subsample ,
@@ -346,7 +346,7 @@ def _check_params(self):
346
346
if self .init is not None :
347
347
# init must be an estimator or 'zero'
348
348
if isinstance (self .init , BaseEstimator ):
349
- self .loss_ .check_init_estimator (self .init )
349
+ self ._loss .check_init_estimator (self .init )
350
350
elif not (isinstance (self .init , str ) and self .init == "zero" ):
351
351
raise ValueError (
352
352
"The init parameter must be an estimator or 'zero'. "
@@ -439,9 +439,9 @@ def _init_state(self):
439
439
440
440
self .init_ = self .init
441
441
if self .init_ is None :
442
- self .init_ = self .loss_ .init_estimator ()
442
+ self .init_ = self ._loss .init_estimator ()
443
443
444
- self .estimators_ = np .empty ((self .n_estimators , self .loss_ .K ), dtype = object )
444
+ self .estimators_ = np .empty ((self .n_estimators , self ._loss .K ), dtype = object )
445
445
self .train_score_ = np .zeros ((self .n_estimators ,), dtype = np .float64 )
446
446
# do oob?
447
447
if self .subsample < 1.0 :
@@ -471,7 +471,7 @@ def _resize_state(self):
471
471
)
472
472
473
473
self .estimators_ = np .resize (
474
- self .estimators_ , (total_n_estimators , self .loss_ .K )
474
+ self .estimators_ , (total_n_estimators , self ._loss .K )
475
475
)
476
476
self .train_score_ = np .resize (self .train_score_ , total_n_estimators )
477
477
if self .subsample < 1 or hasattr (self , "oob_improvement_" ):
@@ -607,7 +607,7 @@ def fit(self, X, y, sample_weight=None, monitor=None):
607
607
# fit initial model and initialize raw predictions
608
608
if self .init_ == "zero" :
609
609
raw_predictions = np .zeros (
610
- shape = (X .shape [0 ], self .loss_ .K ), dtype = np .float64
610
+ shape = (X .shape [0 ], self ._loss .K ), dtype = np .float64
611
611
)
612
612
else :
613
613
# XXX clean this once we have a support_sample_weight tag
@@ -634,7 +634,7 @@ def fit(self, X, y, sample_weight=None, monitor=None):
634
634
else : # regular estimator whose input checking failed
635
635
raise
636
636
637
- raw_predictions = self .loss_ .get_init_raw_predictions (X , self .init_ )
637
+ raw_predictions = self ._loss .get_init_raw_predictions (X , self .init_ )
638
638
639
639
begin_at_stage = 0
640
640
@@ -712,7 +712,7 @@ def _fit_stages(
712
712
do_oob = self .subsample < 1.0
713
713
sample_mask = np .ones ((n_samples ,), dtype = bool )
714
714
n_inbag = max (1 , int (self .subsample * n_samples ))
715
- loss_ = self .loss_
715
+ loss_ = self ._loss
716
716
717
717
if self .verbose :
718
718
verbose_reporter = VerboseReporter (verbose = self .verbose )
@@ -804,10 +804,10 @@ def _raw_predict_init(self, X):
804
804
X = self .estimators_ [0 , 0 ]._validate_X_predict (X , check_input = True )
805
805
if self .init_ == "zero" :
806
806
raw_predictions = np .zeros (
807
- shape = (X .shape [0 ], self .loss_ .K ), dtype = np .float64
807
+ shape = (X .shape [0 ], self ._loss .K ), dtype = np .float64
808
808
)
809
809
else :
810
- raw_predictions = self .loss_ .get_init_raw_predictions (X , self .init_ ).astype (
810
+ raw_predictions = self ._loss .get_init_raw_predictions (X , self .init_ ).astype (
811
811
np .float64
812
812
)
813
813
return raw_predictions
@@ -978,6 +978,15 @@ def apply(self, X):
978
978
def n_features_ (self ):
979
979
return self .n_features_in_
980
980
981
+ # TODO(1.3): Remove
982
+ # mypy error: Decorated property not supported
983
+ @deprecated ( # type: ignore
984
+ "Attribute `loss_` was deprecated in version 1.1 and will be removed in 1.3."
985
+ )
986
+ @property
987
+ def loss_ (self ):
988
+ return self ._loss
989
+
981
990
982
991
class GradientBoostingClassifier (ClassifierMixin , BaseGradientBoosting ):
983
992
"""Gradient Boosting for classification.
@@ -1214,6 +1223,10 @@ class GradientBoostingClassifier(ClassifierMixin, BaseGradientBoosting):
1214
1223
loss_ : LossFunction
1215
1224
The concrete ``LossFunction`` object.
1216
1225
1226
+ .. deprecated:: 1.1
1227
+ Attribute `loss_` was deprecated in version 1.1 and will be
1228
+ removed in 1.3.
1229
+
1217
1230
init_ : estimator
1218
1231
The estimator that provides the initial predictions.
1219
1232
Set via the ``init`` argument or ``loss.init_estimator``.
@@ -1434,7 +1447,7 @@ def predict(self, X):
1434
1447
The predicted values.
1435
1448
"""
1436
1449
raw_predictions = self .decision_function (X )
1437
- encoded_labels = self .loss_ ._raw_prediction_to_decision (raw_predictions )
1450
+ encoded_labels = self ._loss ._raw_prediction_to_decision (raw_predictions )
1438
1451
return self .classes_ .take (encoded_labels , axis = 0 )
1439
1452
1440
1453
def staged_predict (self , X ):
@@ -1456,7 +1469,7 @@ def staged_predict(self, X):
1456
1469
The predicted value of the input samples.
1457
1470
"""
1458
1471
for raw_predictions in self ._staged_raw_predict (X ):
1459
- encoded_labels = self .loss_ ._raw_prediction_to_decision (raw_predictions )
1472
+ encoded_labels = self ._loss ._raw_prediction_to_decision (raw_predictions )
1460
1473
yield self .classes_ .take (encoded_labels , axis = 0 )
1461
1474
1462
1475
def predict_proba (self , X ):
@@ -1482,7 +1495,7 @@ def predict_proba(self, X):
1482
1495
"""
1483
1496
raw_predictions = self .decision_function (X )
1484
1497
try :
1485
- return self .loss_ ._raw_prediction_to_proba (raw_predictions )
1498
+ return self ._loss ._raw_prediction_to_proba (raw_predictions )
1486
1499
except NotFittedError :
1487
1500
raise
1488
1501
except AttributeError as e :
@@ -1534,7 +1547,7 @@ def staged_predict_proba(self, X):
1534
1547
"""
1535
1548
try :
1536
1549
for raw_predictions in self ._staged_raw_predict (X ):
1537
- yield self .loss_ ._raw_prediction_to_proba (raw_predictions )
1550
+ yield self ._loss ._raw_prediction_to_proba (raw_predictions )
1538
1551
except NotFittedError :
1539
1552
raise
1540
1553
except AttributeError as e :
@@ -1781,6 +1794,10 @@ class GradientBoostingRegressor(RegressorMixin, BaseGradientBoosting):
1781
1794
loss_ : LossFunction
1782
1795
The concrete ``LossFunction`` object.
1783
1796
1797
+ .. deprecated:: 1.1
1798
+ Attribute `loss_` was deprecated in version 1.1 and will be
1799
+ removed in 1.3.
1800
+
1784
1801
init_ : estimator
1785
1802
The estimator that provides the initial predictions.
1786
1803
Set via the ``init`` argument or ``loss.init_estimator``.
0 commit comments