All problems
Polynomial Design Matrix
Problem
Build the polynomial regression design matrix for a 1D input x and a given degree: each output row is [1, x_i, x_i^2, ..., x_i^degree].
Return the list of rows; empty x returns [].
Hint
Prepend the bias column of ones, then append powers 1..degree for each value.
Test cases
case 1
in: [[1,2,3],2]
expected: [[1,1,1],[1,2,4],[1,3,9]]
case 2
in: [[0,2],3]
expected: [[1,0,0,0],[1,2,4,8]]
case 3
in: [[-1,1],2]
expected: [[1,-1,1],[1,1,1]]
case 4
in: [[],2]
expected: []
Starter codePython
def polynomial_design_matrix(x, degree):
# Your code here
pass4 test cases · run your code against them in the editor