To solve a standard least squares problem over a training data matrix in MATLAB, you can use the "\ operator".
Assuming you have a training data matrix X and a target variable vector y, you can solve for the linear regression coefficients in the least squares sense using the following code:
main.m397 chars14 lines
The above code generates random training data and target variables, fits a linear regression using the "\ operator", makes predictions on the training data and calculates the residual sum of squares (RSS) and the mean squared error (MSE) measures of model performance. The "\ operator" solves the following standard least squares problem:
main.m32 chars2 lines
where ||.||
denotes the Euclidean norm.
gistlibby LogSnag