"...git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "c34b7ffd3b591b130634eebd544f7bf244e8a8db"
Unverified Commit f585eafa authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[python-package] add type hints on sklearn properties (#5771)

parent 0cff4f83
...@@ -534,7 +534,7 @@ class LGBMModel(_LGBMModelBase): ...@@ -534,7 +534,7 @@ class LGBMModel(_LGBMModelBase):
self._class_map: Optional[Dict[int, int]] = None self._class_map: Optional[Dict[int, int]] = None
self._n_features: int = -1 self._n_features: int = -1
self._n_features_in: int = -1 self._n_features_in: int = -1
self._classes = None self._classes: Optional[np.ndarray] = None
self._n_classes: Optional[int] = None self._n_classes: Optional[int] = None
self.set_params(**kwargs) self.set_params(**kwargs)
...@@ -952,7 +952,7 @@ class LGBMModel(_LGBMModelBase): ...@@ -952,7 +952,7 @@ class LGBMModel(_LGBMModelBase):
return self._Booster.current_iteration() # type: ignore return self._Booster.current_iteration() # type: ignore
@property @property
def booster_(self): def booster_(self) -> Booster:
"""Booster: The underlying Booster of this model.""" """Booster: The underlying Booster of this model."""
if not self.__sklearn_is_fitted__(): if not self.__sklearn_is_fitted__():
raise LGBMNotFittedError('No booster found. Need to call fit beforehand.') raise LGBMNotFittedError('No booster found. Need to call fit beforehand.')
...@@ -966,7 +966,7 @@ class LGBMModel(_LGBMModelBase): ...@@ -966,7 +966,7 @@ class LGBMModel(_LGBMModelBase):
return self._evals_result return self._evals_result
@property @property
def feature_importances_(self): def feature_importances_(self) -> np.ndarray:
""":obj:`array` of shape = [n_features]: The feature importances (the higher, the more important). """:obj:`array` of shape = [n_features]: The feature importances (the higher, the more important).
.. note:: .. note::
...@@ -979,8 +979,8 @@ class LGBMModel(_LGBMModelBase): ...@@ -979,8 +979,8 @@ class LGBMModel(_LGBMModelBase):
return self._Booster.feature_importance(importance_type=self.importance_type) return self._Booster.feature_importance(importance_type=self.importance_type)
@property @property
def feature_name_(self): def feature_name_(self) -> List[str]:
""":obj:`array` of shape = [n_features]: The names of features.""" """:obj:`list` of shape = [n_features]: The names of features."""
if not self.__sklearn_is_fitted__(): if not self.__sklearn_is_fitted__():
raise LGBMNotFittedError('No feature_name found. Need to call fit beforehand.') raise LGBMNotFittedError('No feature_name found. Need to call fit beforehand.')
return self._Booster.feature_name() return self._Booster.feature_name()
...@@ -1195,7 +1195,7 @@ class LGBMClassifier(_LGBMClassifierBase, LGBMModel): ...@@ -1195,7 +1195,7 @@ class LGBMClassifier(_LGBMClassifierBase, LGBMModel):
) )
@property @property
def classes_(self): def classes_(self) -> np.ndarray:
""":obj:`array` of shape = [n_classes]: The class label array.""" """:obj:`array` of shape = [n_classes]: The class label array."""
if not self.__sklearn_is_fitted__(): if not self.__sklearn_is_fitted__():
raise LGBMNotFittedError('No classes found. Need to call fit beforehand.') raise LGBMNotFittedError('No classes found. Need to call fit beforehand.')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment