You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
hasattr(est, 'feature_importances_') should never happen #7481
In some cases, notably TreeClassifier/Regressor and ensembles, feature_importances_ is defined as a property and takes substantial calculation. This violates the assumption that getting an attribute or checking for its presence will be fast, but we can't fix that API design bug in the short term. With properties, a call to hasattr(est, some_attribute) takes as long as getting that attribute: it executes the descriptor's __get__ and hasattr will return True if it runs without error.
This means that if hasattr(est, 'feature_importances_'): do something with est.feature_importances_ is slow. We need to replace these (in SelectFromModel and RFE) with getattr(obj, feature_importances_, DUMMY) or something.
We should look for other cases where hasattr is used to check for model attributes that may be defined by expensive descriptors.
Activity
fukatani commentedon Sep 24, 2016
I'm interested in this issue and working on it!