Skip to content

Commit

Permalink
[python] add more type hints on LGBMModel methods (#5239)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb authored May 31, 2022
1 parent 9893867 commit 4971a06
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions python-package/lightgbm/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def __init__(
self._n_classes = None
self.set_params(**kwargs)

def _more_tags(self):
def _more_tags(self) -> Dict[str, Any]:
return {
'allow_nan': True,
'X_types': ['2darray', 'sparse', '1dlabels'],
Expand All @@ -520,7 +520,7 @@ def _more_tags(self):
def __sklearn_is_fitted__(self) -> bool:
return getattr(self, "fitted_", False)

def get_params(self, deep=True):
def get_params(self, deep: bool = True) -> Dict[str, Any]:
"""Get parameters for this estimator.
Parameters
Expand All @@ -538,7 +538,7 @@ def get_params(self, deep=True):
params.update(self._other_params)
return params

def set_params(self, **params):
def set_params(self, **params: Any) -> "LGBMModel":
"""Set the parameters of this estimator.
Parameters
Expand Down Expand Up @@ -823,14 +823,14 @@ def predict(self, X, raw_score=False, start_iteration=0, num_iteration=None,
)

@property
def n_features_(self):
def n_features_(self) -> int:
""":obj:`int`: The number of features of fitted model."""
if not self.__sklearn_is_fitted__():
raise LGBMNotFittedError('No n_features found. Need to call fit beforehand.')
return self._n_features

@property
def n_features_in_(self):
def n_features_in_(self) -> int:
""":obj:`int`: The number of features of fitted model."""
if not self.__sklearn_is_fitted__():
raise LGBMNotFittedError('No n_features_in found. Need to call fit beforehand.')
Expand All @@ -844,14 +844,14 @@ def best_score_(self):
return self._best_score

@property
def best_iteration_(self):
def best_iteration_(self) -> int:
""":obj:`int`: The best iteration of fitted model if ``early_stopping()`` callback has been specified."""
if not self.__sklearn_is_fitted__():
raise LGBMNotFittedError('No best_iteration found. Need to call fit with early_stopping callback beforehand.')
return self._best_iteration

@property
def objective_(self):
def objective_(self) -> Union[str, _LGBM_ScikitCustomObjectiveFunction]:
""":obj:`str` or :obj:`callable`: The concrete objective used while fitting this model."""
if not self.__sklearn_is_fitted__():
raise LGBMNotFittedError('No objective found. Need to call fit beforehand.')
Expand Down Expand Up @@ -1088,7 +1088,7 @@ def classes_(self):
return self._classes

@property
def n_classes_(self):
def n_classes_(self) -> int:
""":obj:`int`: The number of classes."""
if not self.__sklearn_is_fitted__():
raise LGBMNotFittedError('No classes found. Need to call fit beforehand.')
Expand Down

0 comments on commit 4971a06

Please sign in to comment.