2
$\begingroup$

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.

$\endgroup$
2
  • 2
    $\begingroup$ What you have above is: [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$
    – sshashank124
    Commented Jan 11, 2020 at 8:40
  • $\begingroup$ that 1 is for scale shifts detection. Intuitionally, take that as allowing the math to include outer dimensional forces, which doesn't relate with those variables a or b, or their compositions, which thus are constant. $\endgroup$
    – Vicrobot
    Commented Jan 11, 2020 at 8:41

1 Answer 1

1
$\begingroup$

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$).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.