All problems
Polynomial Feature Value
Problem
Build the polynomial feature vector [1, x, x^2, ..., x^degree] for a scalar input.
Hint
The constant 1 feature lets the linear weights carry a bias.
Test cases
case 1
in: [2,3]
expected: [1,2,4,8]
case 2
in: [0.5,2]
expected: [1,0.5,0.25]
case 3
in: [-1,1]
expected: [1,-1]
case 4
in: [3,0]
expected: [1]
Starter codePython
def polynomial_features(x, degree):
# Your code here
pass4 test cases · run your code against them in the editor