user3306125
user3306125

Reputation: 215

How to find new features in sklearn?

Does sk-learn have any method that finds new features by aggregating already existing features in dataset? I mean something like this one: foobar=foo/bar

Upvotes: 2

Views: 587

Answers (1)

elyase
elyase

Reputation: 40973

The only thing that comes to mind is PolynomialFeatures:

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]

Example:

>>> X = np.array([[0, 1],
                  [2, 3],
                  [4, 5]])
>>> poly = PolynomialFeatures(2)
>>> poly.fit_transform(X)
array([[ 1,  0,  1,  0,  0,  1],
       [ 1,  2,  3,  4,  6,  9],
       [ 1,  4,  5, 16, 20, 25]])

Upvotes: 1

Related Questions