Skip to content

Commit

Permalink
MNT hasattr->getattr on coef_ (scikit-learn#11698)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinjalali authored and jnothman committed Aug 12, 2018
1 parent a955da1 commit dd700f4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sklearn/feature_selection/from_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ def _get_feature_importances(estimator, norm_order=1):
"""Retrieve or aggregate feature importances from estimator"""
importances = getattr(estimator, "feature_importances_", None)

if importances is None and hasattr(estimator, "coef_"):
coef_ = getattr(estimator, "coef_", None)
if importances is None and coef_ is not None:
if estimator.coef_.ndim == 1:
importances = np.abs(estimator.coef_)
importances = np.abs(coef_)

else:
importances = np.linalg.norm(estimator.coef_, axis=0,
importances = np.linalg.norm(coef_, axis=0,
ord=norm_order)

elif importances is None:
Expand Down

0 comments on commit dd700f4

Please sign in to comment.