← All problems
#33 Ordinary Least Squares Medium

Solve the Ordinary Least Squares (OLS) regression problem on a GPU. Given a feature matrix \(X\) of size \(n\_samples \times n\_features\) and a target vector \(y\) of size \(n\_samples\), compute the coefficient vector \(\beta\) that minimizes the sum of squared residuals: \[ \min_{\beta} ||X\beta - y||^2 \] The closed-form solution to OLS is: \[ \beta = (X^TX)^{-1}X^Ty \]

Implementation Requirements

Example:

Input:
\(X\) (samples × features): \[ \begin{bmatrix} -0.23 & -0.23 & 1.52 \\ 0.77 & -0.47 & 1.58 \\ -0.14 & 0.65 & 0.5 \\ -1.91 & -1.72 & 0.24 \\ -0.46 & -0.47 & 0.54 \end{bmatrix} \] \(y\): \[ \begin{bmatrix} 83.01 \\ 93.4 \\ 47.33 \\ -62.22 \\ 13.06 \end{bmatrix} \] Output:
\(\beta\): \[ \begin{bmatrix} 13.97 \\ 29.12 \\ 61.05 \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.