2

I am trying the use feature_names_out on scikit's FunctionTransformer to get the same feature names but I get this error:

Code:

from sklearn.preprocessing import FunctionTransformer

X = pd.Series(data=[1, 2, 3], name='numbers')
transformer = FunctionTransformer(np.log, feature_names_out='one-to-one')

Error:

TypeError                                 Traceback (most recent call last)
Cell 8 in <cell line: 5>()
      1 from sklearn.preprocessing import FunctionTransformer
      4 X = pd.Series(data=[1, 2, 3], name='numbers')
----> 5 transformer = FunctionTransformer(np.log, feature_names_out='one-to-one')
      7 transformer.transform(X)

TypeError: __init__() got an unexpected keyword argument 'feature_names_out'
desertnaut
  • 57,590
  • 26
  • 140
  • 166
saad
  • 31
  • 3

1 Answers1

3

Please check the version of scikit-learn. feature_names_out was added only in version 1.1 so you may need to update scikit-learn.

From the official documentation:

feature_names_out : callable, ‘one-to-one’ or None, default=None

New in version 1.1.

You can check the version with the following code:

import sklearn
print(sklearn.__version__)

or using pip:

pip freeze | grep scikit
desertnaut
  • 57,590
  • 26
  • 140
  • 166
u1234x1234
  • 2,062
  • 1
  • 1
  • 8