diff --git a/python-package/xgboost/sklearn.py b/python-package/xgboost/sklearn.py index 5f8ff852e..f874a63bc 100644 --- a/python-package/xgboost/sklearn.py +++ b/python-package/xgboost/sklearn.py @@ -328,6 +328,20 @@ class XGBModel(XGBModelBase): return evals_result + @property + def feature_importances_(self): + """ + Returns + ------- + feature_importances_ : array of shape = [n_features] + + """ + b = self.booster() + fs = b.get_fscore() + all_features = [fs.get(f, 0.) for f in b.feature_names] + all_features = np.array(all_features, dtype=np.float32) + return all_features / all_features.sum() + class XGBClassifier(XGBModel, XGBClassifierBase): # pylint: disable=missing-docstring,too-many-arguments,invalid-name @@ -518,20 +532,6 @@ class XGBClassifier(XGBModel, XGBClassifierBase): return evals_result - @property - def feature_importances_(self): - """ - Returns - ------- - feature_importances_ : array of shape = [n_features] - - """ - b = self.booster() - fs = b.get_fscore() - all_features = [fs.get(f, 0.) for f in b.feature_names] - all_features = np.array(all_features, dtype=np.float32) - return all_features / all_features.sum() - class XGBRegressor(XGBModel, XGBRegressorBase): # pylint: disable=missing-docstring