Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a15c336

Browse files
authored
MNT Remove redundant _check_initialized method (#34519)
1 parent c427b09 commit a15c336

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

sklearn/ensemble/_gb.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,6 @@ def _resize_state(self):
597597
def _is_fitted(self):
598598
return len(getattr(self, "estimators_", [])) > 0
599599

600-
def _check_initialized(self):
601-
"""Check that the estimator is initialized, raising an error if not."""
602-
check_is_fitted(self)
603-
604600
@_fit_context(
605601
# GradientBoosting*.init is not validated yet
606602
prefer_skip_nested_validation=False
@@ -948,7 +944,6 @@ def _make_estimator(self, append=True):
948944

949945
def _raw_predict_init(self, X):
950946
"""Check input and compute raw predictions of the init estimator."""
951-
self._check_initialized()
952947
X = self.estimators_[0, 0]._validate_X_predict(X, check_input=True)
953948
if self.init_ == "zero":
954949
raw_predictions = np.zeros(
@@ -991,6 +986,7 @@ def _staged_raw_predict(self, X, check_input=True):
991986
Regression and binary classification are special cases with
992987
``k == 1``, otherwise ``k==n_classes``.
993988
"""
989+
check_is_fitted(self)
994990
if check_input:
995991
X = validate_data(
996992
self, X, dtype=np.float32, order="C", accept_sparse="csr", reset=False
@@ -1020,7 +1016,7 @@ def feature_importances_(self):
10201016
trees consisting of only the root node, in which case it will be an
10211017
array of zeros.
10221018
"""
1023-
self._check_initialized()
1019+
check_is_fitted(self)
10241020

10251021
relevant_trees = [
10261022
tree
@@ -1103,7 +1099,7 @@ def apply(self, X):
11031099
In the case of binary classification n_classes is 1.
11041100
"""
11051101

1106-
self._check_initialized()
1102+
check_is_fitted(self)
11071103
X = self.estimators_[0, 0]._validate_X_predict(X, check_input=True)
11081104

11091105
# n_classes will be equal to 1 in the binary classification or the

0 commit comments

Comments
 (0)