how to the remove interaction-only columns from sklearn.preprocessing.PolynomialFeatures
Asked Answered
C

1

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?

Cytherea answered 10/2, 2018 at 2:14 Comment(0)
A
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)
Acro answered 11/2, 2018 at 8:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.