Options
All
  • Public
  • Public/Protected
  • All
Menu

Transforms feature vectors to vectors of certain monomials thereof.

E.g. after setting options (degree, homogeneous, interactionOnly), and *fit()*ing, *transform()*s lists of feature vectors like [a, b, c], where a, b and c are numbers, into the following possible outputs

  • [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 in a, b, c of degree exactly equal to two.

  • [ab, ac, bc] (degree = 2, homogeneous = true, interactionOnly = true), that is, all monomials in a, b, c 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 in a, b, c 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().

Hierarchy

  • PolynomialFeatures

Index

Constructors

  • new PolynomialFeatures(degree?: number, homogeneous?: boolean, interactionOnly?: boolean): PolynomialFeatures
  • 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

    • Optional degree: 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

Properties

_degree: number
_homogeneous: boolean
_interactionOnly: boolean
_nFeaturesIn: number

Accessors

  • get config(): PolynomialFeaturesConfig
  • Saves configuration to a simple option-bag.

    The configuration specifies the internal state of PolynomialFeatures completely. Hence the config of the transformer can be used to save it to a file.

    Returns PolynomialFeaturesConfig

  • get degree(): number
  • get homogenous(): boolean
  • get interactionOnly(): boolean
  • get nFeaturesIn(): number

Methods

  • assertValidConfig(): void
  • fit(x: number[][]): void
  • 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

  • fitTransform(x: number[][]): number[][]
  • Same as applying first fit(...) and then transform(...) to x.

    Parameters

    • x: number[][]

      List of features vectors.

    Returns number[][]

  • fromConfig(config: PolynomialFeaturesConfig): void
  • transform(x: number[][]): 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[][]

Generated using TypeDoc