TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Polynomial Features

Feature Engineering
Easy

Polynomial feature expansion represents one numeric value using successive powers. This allows a linear model to learn relationships such as curves when the expanded values are supplied as separate features.

For each input value, generate powers from zero through degree:

ϕ(x)=[1,x,x2,…,xd]\phi(x) = [1, x, x^2, \ldots, x^d]ϕ(x)=[1,x,x2,…,xd]

Here, x is an input value, d is the maximum degree, and the resulting vector is the expanded feature row. The first element is always 1 and serves as the intercept feature. Return one row containing degree + 1 values for every input value.

Loading visualization...

Examples

Input: values = [2, 3], degree = 2

Output: [[1, 2, 4], [1, 3, 9]]

Explanation: Each row contains powers zero, one, and two of its input value.

Input: values = [-2], degree = 3

Output: [[1, -2, 4, -8]]

Hint 1

Use range through degree inclusive for each input value.

Hint 2

Raise the value to every exponent, including zero for the intercept feature.

Requirements

  • For each value, generate powers from 0 to degree (inclusive)
  • Include x^0 = 1 as the first element (bias term)
  • Return a list of lists where each inner list has degree + 1 elements

Constraints

  • values has at least 1 element
  • degree >= 0
  • Return a list of lists of numbers
  • Time limit: 300 ms
Try Similar Problems
Interaction FeaturesLog TransformRank TransformBinningFrequency Encoding

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

You must run your code first.
PrevNext

Polynomial Features

Feature Engineering
Easy

Polynomial feature expansion represents one numeric value using successive powers. This allows a linear model to learn relationships such as curves when the expanded values are supplied as separate features.

For each input value, generate powers from zero through degree:

ϕ(x)=[1,x,x2,…,xd]\phi(x) = [1, x, x^2, \ldots, x^d]ϕ(x)=[1,x,x2,…,xd]

Here, x is an input value, d is the maximum degree, and the resulting vector is the expanded feature row. The first element is always 1 and serves as the intercept feature. Return one row containing degree + 1 values for every input value.

Loading visualization...

Examples

Input: values = [2, 3], degree = 2

Output: [[1, 2, 4], [1, 3, 9]]

Explanation: Each row contains powers zero, one, and two of its input value.

Input: values = [-2], degree = 3

Output: [[1, -2, 4, -8]]

Hint 1

Use range through degree inclusive for each input value.

Hint 2

Raise the value to every exponent, including zero for the intercept feature.

Requirements

  • For each value, generate powers from 0 to degree (inclusive)
  • Include x^0 = 1 as the first element (bias term)
  • Return a list of lists where each inner list has degree + 1 elements

Constraints

  • values has at least 1 element
  • degree >= 0
  • Return a list of lists of numbers
  • Time limit: 300 ms
Try Similar Problems
Interaction FeaturesLog TransformRank TransformBinningFrequency Encoding

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

You must run your code first.