Linear regression finds the weight vector that minimizes the sum of squared errors between predictions and targets. The closed-form solution (the normal equation) computes the optimal weights directly using matrix algebra, without iterative optimization.
Given a feature matrix X and a target vector y, compute the weight vector w using the normal equation.
Where X is the n×d feature matrix (n samples, d features), y is the n-dimensional target vector, and w is the d-dimensional weight vector.
Return the weight vector as a list of floats with one value per feature column.
Input: X = [[1], [2], [3]], y = [2, 4, 6]
Output: [2.0]
Explanation: The single weight 2 exactly maps each feature value to its target.
Input: X = [[1, 1], [1, 2], [1, 3]], y = [3, 5, 7]
Output: [1.0, 2.0]
Convert X and y to float64 NumPy arrays.
Apply matrix multiplication in the same order as the normal equation.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Linear regression finds the weight vector that minimizes the sum of squared errors between predictions and targets. The closed-form solution (the normal equation) computes the optimal weights directly using matrix algebra, without iterative optimization.
Given a feature matrix X and a target vector y, compute the weight vector w using the normal equation.
Where X is the n×d feature matrix (n samples, d features), y is the n-dimensional target vector, and w is the d-dimensional weight vector.
Return the weight vector as a list of floats with one value per feature column.
Input: X = [[1], [2], [3]], y = [2, 4, 6]
Output: [2.0]
Explanation: The single weight 2 exactly maps each feature value to its target.
Input: X = [[1, 1], [1, 2], [1, 3]], y = [3, 5, 7]
Output: [1.0, 2.0]
Convert X and y to float64 NumPy arrays.
Apply matrix multiplication in the same order as the normal equation.
Sign in to take notes on this problem
Accepts: array
Accepts: array