scikit-learn 0.18 添加了一个漂亮的get_feature_names() http://scikit-learn.org/0.18/modules/generated/sklearn.preprocessing.PolynomialFeatures.html#sklearn.preprocessing.PolynomialFeatures.get_feature_names method!
>> input_df.columns
Index(['a', 'b', 'c'], dtype='object')
>> poly.fit_transform(input_df)
array([[ 1., 1., 2., 3., 1., 2., 3., 4., 6., 9.],
[ 1., 1., 2., 3., 1., 2., 3., 4., 6., 9.],
[ 1., 1., 2., 3., 1., 2., 3., 4., 6., 9.]])
>> poly.get_feature_names(input_df.columns)
['1', 'a', 'b', 'c', 'a^2', 'a b', 'a c', 'b^2', 'b c', 'c^2']
请注意,您必须为其提供列名称,因为 sklearn 不会自行从 DataFrame 中读取它。