← All problems
#34 Logistic Regression Medium

Solve the logistic regression problem on a GPU. Given a feature matrix \(X\) of size \(n\_samples \times n\_features\) and a binary target vector \(y\) of size \(n\_samples\) (containing only 0s and 1s), compute the coefficient vector \(\beta\) that maximizes the log-likelihood: \[ \max_{\beta} \sum_{i=1}^{n} \left[ y_i \log(p_i) + (1-y_i) \log(1-p_i) \right] \] where \(p_i = \sigma(X_i^T \beta)\) and \(\sigma(z) = \frac{1}{1 + e^{-z}}\) is the sigmoid function.

Implementation Requirements

Example:

Input:
\(X\) (samples × features): \[ \begin{bmatrix} 2.0 & 1.0 \\ 1.0 & 2.0 \\ 3.0 & 3.0 \\ 1.5 & 2.5 \\ -1.0 & -2.0 \\ -2.0 & -1.0 \\ -1.5 & -2.5 \\ -3.0 & -3.0 \end{bmatrix} \] \(y\): \[ \begin{bmatrix} 1 \\ 1 \\ 1 \\ 0 \\ 0 \\ 0 \\ 1 \\ 0 \end{bmatrix} \] Output:
\(\beta\): \[ \begin{bmatrix} 2.26 \\ -1.29 \end{bmatrix} \]

Constraints

Guided walkthrough coming soon. Below is the official starter signature in each language; the clickable line-by-line explanation hasn't been authored yet.
Problem text & starters from the official AlphaGPU/leetgpu-challenges. Solve it on leetgpu.com.