Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-304

Partial Dependence 1D

Problem

Compute the 1D partial dependence of a linear model: for each grid value v, average w[feature]*v plus the other weighted features over all rows.

Return [] if X or the grid is empty.

Hint

Partial dependence marginalizes the model over the other features.

Test cases

case 1
in: [[[1,2],[2,3]],[1,1],0,[0,10]]
expected: [2.5,12.5]
case 2
in: [[[1,2],[2,3]],[1,1],1,[0,10]]
expected: [1.5,11.5]
case 3
in: [[],[1,1],0,[0,10]]
expected: []
case 4
in: [[[1,2]],[1,1],0,[]]
expected: []
Starter codePython
def partial_dependence(X, w, feature, grid_values):
    # Your code here
    pass

4 test cases · run your code against them in the editor