← 返回 microsoft 的题目列表ML Coding: Implement a basic ML-related routine
类型:online_judge
Problem: ML Coding - Train and Predict with Binary Logistic Regression
Implement logistic regression from scratch using batch gradient descent, then predict labels on a test set.
Model
( p(y=1|x) = \sigma(w^T x + b) )
(\sigma(z)=1/(1+e^{-z}))
Loss: average negative log-likelihood (cross-entropy)
Input (stdin)
n_train n_test d
Next n_train lines: d features followed by label y (0/1)
Next n_test lines: d features
Last line: lr epochs
Output
Print n_test lines, each a predicted label (0/1). Use threshold 0.5.
Constraints
1 <= n_train, n_test <= 2000
1 <= d <= 50
0 < lr <= 1
1 <= epochs <= 2000
Example
Input:
4 2 2
0 0 0
0 1 0
1 0 0
1 1 1
0 0
1 1
0.5 200
Output:
0
1
Example
Input
4 2 2
0 0 0
0 1 0
1 0 0
1 1 1
0 0
1 1
0.5 200
Output
0
1