Define feature_names_in_. (#7526)
* Define `feature_names_in_`. * Raise attribute error if it's not defined.
This commit is contained in:
@@ -1105,6 +1105,18 @@ class XGBModel(XGBModelBase):
|
||||
booster = self.get_booster()
|
||||
return booster.num_features()
|
||||
|
||||
@property
|
||||
def feature_names_in_(self) -> np.ndarray:
|
||||
"""Names of features seen during :py:meth:`fit`. Defined only when `X` has feature
|
||||
names that are all strings."""
|
||||
feature_names = self.get_booster().feature_names
|
||||
if feature_names is None:
|
||||
raise AttributeError(
|
||||
"`feature_names_in_` is defined only when `X` has feature names that "
|
||||
"are all strings."
|
||||
)
|
||||
return np.array(feature_names)
|
||||
|
||||
def _early_stopping_attr(self, attr: str) -> Union[float, int]:
|
||||
booster = self.get_booster()
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user