Branch data Line data Source code
1 : : #pragma once 2 : : 3 : : #include <Eigen/Core> 4 : : #include <Eigen/LU> 5 : : 6 : : 7 : : namespace m { 8 : : 9 : : /** Use closed-form solution for linear regression 10 : : * @param X the feature matrix 11 : : * @param y the target vector 12 : : * @return a vector of coefficients that represent the linear model 13 : : */ 14 : 2 : Eigen::VectorXd regression_linear_closed_form(const Eigen::MatrixXd &X, const Eigen::VectorXd &y) 15 : : { 16 : 2 : return (X.transpose() * X).inverse() * X.transpose() * y; 17 : : } 18 : : 19 : : }