Skip to content

Commit

Permalink
Add notes to doc (dmlc#3765)
Browse files Browse the repository at this point in the history
  • Loading branch information
hcho3 authored Oct 7, 2018
1 parent 91903ac commit c23783a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions python-package/xgboost/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,10 @@ def __init__(self, params=None, cache=(), model_file=None):
ctypes.byref(self.handle)))
self.set_param({'seed': 0})
self.set_param(params or {})
if (params is not None) and ('booster' in params):
self.booster = params['booster']
else:
self.booster = 'gbtree'
if model_file is not None:
self.load_model(model_file)

Expand Down Expand Up @@ -1379,6 +1383,12 @@ def get_dump(self, fmap='', with_stats=False, dump_format="text"):
def get_fscore(self, fmap=''):
"""Get feature importance of each feature.
.. note:: Feature importance is defined only for tree boosters
Feature importance is only defined when the decision tree model is chosen as base
learner (`booster=gbtree`). It is not defined for other base learner types, such
as linear learners (`booster=gblinear`).
Parameters
----------
fmap: str (optional)
Expand All @@ -1397,6 +1407,12 @@ def get_score(self, fmap='', importance_type='weight'):
* 'total_gain': the total gain across all splits the feature is used in.
* 'total_cover': the total coverage across all splits the feature is used in.
.. note:: Feature importance is defined only for tree boosters
Feature importance is only defined when the decision tree model is chosen as base
learner (`booster=gbtree`). It is not defined for other base learner types, such
as linear learners (`booster=gblinear`).
Parameters
----------
fmap: str (optional)
Expand All @@ -1405,6 +1421,10 @@ def get_score(self, fmap='', importance_type='weight'):
One of the importance types defined above.
"""

if self.booster != 'gbtree':
raise ValueError('Feature importance is not defined for Booster type {}'
.format(self.booster))

allowed_importance_types = ['weight', 'gain', 'cover', 'total_gain', 'total_cover']
if importance_type not in allowed_importance_types:
msg = ("importance_type mismatch, got '{}', expected one of " +
Expand Down
6 changes: 6 additions & 0 deletions python-package/xgboost/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,12 @@ def feature_importances_(self):
"""
Feature importances property
.. note:: Feature importance is defined only for tree boosters
Feature importance is only defined when the decision tree model is chosen as base
learner (`booster=gbtree`). It is not defined for other base learner types, such
as linear learners (`booster=gblinear`).
Returns
-------
feature_importances_ : array of shape ``[n_features]``
Expand Down

0 comments on commit c23783a

Please sign in to comment.