Skip to content

Commit 1bf86ec

Browse files
remo-helpdesilinguist
authored andcommitted
Add new Learner method for getting feature names.
Added a utility method to the Learner class, allowing it to return an array of feature names after the selector step.
1 parent bdf6107 commit 1bf86ec

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

skll/learner/__init__.py

+18
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,24 @@ def _create_estimator(self):
640640

641641
return estimator, default_param_grid
642642

643+
def get_feature_names_out(self):
644+
"""
645+
Return the names of the actual features used by the estimator.
646+
647+
It is possible for some features to get filtered out by the
648+
feature selector which means that the vectorizer is no
649+
longer the correct source for the feature names. This
650+
method takes into account the feature selector and returns
651+
the names of the features that were actually selected to be
652+
used by the estimator.
653+
654+
Returns
655+
-------
656+
names : 1-D array
657+
Names of features actually used by the estimator.
658+
"""
659+
return self.feat_vectorizer.get_feature_names_out()[self.feat_selector.get_support()]
660+
643661
def _check_input_formatting(self, examples):
644662
"""
645663
check that the examples are properly formatted.

0 commit comments

Comments
 (0)