-
-
Save caiorss/d78211e4ad7d0b81dc44724ceb4aafd4 to your computer and use it in GitHub Desktop.
Linear Regression in Matlab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [m b] = linear_regression(X, Y) | |
n = length(Y); | |
EX = sum(X); | |
EY = sum(Y); | |
EX2 = sum(X.*X); | |
EXY = sum(X.*Y); | |
m = (n*EXY - EX*EY) / (n*EX2 - EX*EX); | |
b = (EY - m*EX) / n; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment