I don't understand why the output of scikit's PolynomialFeatuers' degree always has a one.
Example for degree=2 and [a, b], output is
[1, a, b, a^2, b^2, ab]
I don't know why it always has a 1.
A few things to add:
An $n$-th degree univariate polynomial is of the form $\sum_{i=0}^n a_ix^i$, which includes the bias term (i.e. $1=x^0$), even if it can be zero.
sklearn
has the option to omit the bias term via include_bias
option. When set to False
, you won't see any $1$'s.
As commented by @sshashank124 you'll have each term's exponent $\leq$ n, if you have $k$ features (i.e. $x_1\dots x_k$), the terms will be of the form: $\prod_{i=1}^k x_i^{n_i}$, where $\sum_{i=1}^k n_i\leq n$.
This sometimes produces lots of features, specifically:
${{n+k}\choose {n}}$.
You may also want to use interaction_only
parameter to only get the interactions (i.e. terms with each feature degree having at most $1$).
[a^0 * b^0, a^1 * b^0, a^0 * b^1, a^2 * b^0, a^0 * b^2, a^1 * b^1]
$\endgroup$