All problems
Logistic Propensity Score
Problem
Return the logistic propensity score 1/(1+exp(-z)) with z = coefficients[0] + sum(coefficients[j+1]*features[j]). Return 0.0 when coefficients does not have exactly len(features) + 1 entries. Handle large negative z without overflow.
Hint
Compute the linear predictor, then squash it through the sigmoid.
Test cases
case 1
in: [[1,2],[-1,0.5,1]]
expected: 0.8175744761936437
case 2
in: [[0],[0,1]]
expected: 0.5
case 3
in: [[5],[0,-10]]
expected: 1.9287498479639178e-22
case 4
in: [[1],[0]]
expected: 0
case 5
in: [[],[0]]
expected: 0.5
Starter codePython
import math
def logistic_propensity(features, coefficients):
# Your code here
pass5 test cases · run your code against them in the editor