Skip to content

Commit

Permalink
address get_feature_names to get_feature_names_out API change
Browse files Browse the repository at this point in the history
  • Loading branch information
gregcaporaso committed Apr 30, 2024
1 parent 54eed98 commit 1f561d3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion q2_sample_classifier/tests/test_estimators.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_extract_features(self):
dv = DictVectorizer()
dv.fit(dicts)
features = table.ids('observation')
self.assertEqual(set(dv.get_feature_names()), set(features))
self.assertEqual(set(dv.get_feature_names_out()), set(features))
self.assertEqual(len(dicts), len(table.ids()))
for dict_row, (table_row, _, _) in zip(dicts, table.iter()):
for feature, count in zip(features, table_row):
Expand Down
8 changes: 4 additions & 4 deletions q2_sample_classifier/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def _rfecv_feature_selection(feature_data, targets, estimator,
# Describe top features
n_opt = rfecv.named_steps.est.n_features_
importance = _extract_important_features(
rfecv.named_steps.dv.get_feature_names(),
rfecv.named_steps.dv.get_feature_names_out(),
rfecv.named_steps.est.ranking_)
importance = sort_importances(importance, ascending=True)[:n_opt]

Expand Down Expand Up @@ -411,12 +411,12 @@ def _calculate_feature_importances(estimator):
# feature_importances_ or coef_ to report feature importance/weights
try:
importances = _extract_important_features(
estimator.named_steps.dv.get_feature_names(),
estimator.named_steps.dv.get_feature_names_out(),
estimator.named_steps.est.feature_importances_)
# is there a better way to determine whether estimator has coef_ ?
except AttributeError:
importances = _extract_important_features(
estimator.named_steps.dv.get_feature_names(),
estimator.named_steps.dv.get_feature_names_out(),
estimator.named_steps.est.coef_)
return importances

Expand Down Expand Up @@ -718,7 +718,7 @@ def _mean_feature_importance(importances):
def _null_feature_importance(table):
feature_extractor = DictVectorizer()
feature_extractor.fit(table)
imp = pd.DataFrame(index=feature_extractor.get_feature_names())
imp = pd.DataFrame(index=feature_extractor.get_feature_names_out())
imp.index.name = "feature"
imp["importance"] = 1
return imp
Expand Down

0 comments on commit 1f561d3

Please sign in to comment.