Moritz - 11 months ago 177

Python Question

I now, it is possible to obtain the polynomial features as numbers by

`polynomial_features.transform(X)`

`[1, a, b, a^2, ab, b^2]`

`.get_params()`

Answer Source

```
import numpy as np
from sklearn.preprocessing import PolynomialFeatures
X = np.array([2,3])
poly = PolynomialFeatures(3)
Y = poly.fit_transform(X)
print Y
# prints [[ 1 2 3 4 6 9 8 12 18 27]]
print poly.powers_
```

This code will print:

```
[[0 0]
[1 0]
[0 1]
[2 0]
[1 1]
[0 2]
[3 0]
[2 1]
[1 2]
[0 3]]
```

So if the i'th cell is `(x,y)`

, that means that `Y[i]=(a**x)*(b**y)`

.
For instance, in the code example `[2 1]`

equals to `(2**2)*(3**1)=12`

.