def custom_fnames(union):
feature_names = []
for name, trans, weight in union._iter():
if hasattr(trans, 'get_feature_names'):
this_fn = trans.get_feature_names()
elif isinstance(trans, Pipeline):
# we use pipelines to scale only specific attributes.
# In this case, the vectorizer is first in the pipe.
this_fn = trans.steps[0][-1].get_feature_names()
else:
raise AttributeError("Transformer %s (type %s) does not "
"provide get_feature_names." % (
str(name), type(trans).__name__))
feature_names.extend([name + "__" + f for f in this_fn])
return feature_names
评论列表
文章目录