Transforms feature vectors to vectors of certain monomials thereof.

Example: Consider a feature vector [a, b, c]. After executing fitTransform you get

  • [a^2, ba, ca, a, b^2, cb, b, c^2, c, 1] (degree = 2), that is, all monomials in a, b, c up to degree two.
  • [a^2, ba, ca, b^2, cb, c^2] (degree = 2, homogeneous = true), that is, all monomials of degree exactly equal to two.
  • [ab, ac, bc] (degree = 2, homogeneous = true, interactionOnly = true), that is, all monomials of degree exactly equal to two and no feature raised to a power larger than one.
  • [ab, ac, a, bc, b, c, 1] (degree = 2, homogeneous = false, interactionOnly = true), that is, all monomials of degree at most two and no feature raised to a power larger than one.

Of course, the number of features is not restricted to three, but must be the same in each feature vector of the list to be transformed.

Constructors

  • Basic configuration. You can skip configuration by providing no arguments.

    In case no arguments are given you have to use the method fromConfig to set up a configuration in order to use the methods fit, transform and fitTransform.

    Parameters

    • Optionaldegree: number

      Highest order of the monomials

    • homogeneous: boolean = false

      Whether to include only highest order monomials

    • interactionOnly: boolean = false

      Whether to disallow higher powers of single features

    Returns PolynomialFeatures

Accessors

  • get nFeaturesIn(): number
  • Number of input features.

    The only configuration option which is set by the fit method.

    Returns number

Methods

  • Sets the number of input features.

    Call this method before transform. Afterwards the transform method will only accept input with the correct number of features.

    Parameters

    • x: number[][]

    Returns void

  • Same as applying first fit and then transform to x.

    Parameters

    • x: number[][]

      List of features vectors.

    Returns number[][]

  • Returns the list of polynomial features corresponding to x.

    Parameters

    • x: number[][]

      List of features vectors (with same number of features each).

    Returns number[][]