Logistic Regression
Medium
Logistic Classifier Predictions
Medium
~15 min
code completion
Logistic Regression Prediction
Logistic regression converts a linear score into a binary prediction:
1. Compute the linear combination:
2. Apply sigmoid:
3. Threshold:
The default threshold is 0.5, but it can be adjusted to trade precision vs. recall.
Your task:
Implement logistic_predict(X, weights, threshold) that returns an integer array of 0s and 1s.
Example Tests
Zero input: sigmoid=0.5, above default threshold
Input: {"X":[[0],[10],[-10]],"weights":[1],"threshold":0.5}
Expected: [1,1,0]
Negative scores: all predict 0
Input: {"X":[[1,2],[3,4]],"weights":[0.5,-1],"threshold":0.5}
Expected: [0,0]
Raised threshold makes prediction stricter
Input: {"X":[[0],[0],[10]],"weights":[1],"threshold":0.8}
Expected: [0,0,1]