2

As per the description given below: 'if an input sample is two dimensional and of the form [a, b], the degree-2 polynomial features are [1, a, b, a^2, ab, b^2].'

sklearn.preprocessing.PolynomialFeatures

I need my output ndarray generated to be of the type: [a, b, a^2, b^2] I know that poly = PolynomialFeatures(2, include_bias=False) poly.fit_transform(X) gives the output like : [a, b, a^2, ab, b^2]. But I do not want these intermediate 'ab' type columns that are being generated. How to do that any idea? Or any better API that can be used here?

user3868051
  • 1,147
  • 2
  • 22
  • 43

1 Answers1

2

Check out patsy and this scikit-learn integration patsylearn.

This gives you full control in a R-like formula:

from patsylearn import PatsyTransformer
transformer = PatsyTransformer("y ~ a + b + a^2 + b^2")
transformer.fit(data)
Marcus V.
  • 6,323
  • 1
  • 18
  • 33