Created
October 28, 2011 17:39
-
-
Save timjb/1322849 to your computer and use it in GitHub Desktop.
AI class: Linear Regression
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
| -- https://www.ai-class.com/course/video/quizquestion/127 | |
| module LinearRegression where | |
| computeLR :: [(Double, Double)] -> (Double, Double) | |
| computeLR vs = (w0, w1) | |
| where w1 = enum / denom | |
| enum = m * (sum $ zipWith (*) xs ys) - (sum xs) * (sum ys) | |
| denom = m * (sum . map (^2) $ xs) - (sum xs)^2 | |
| w0 = (sum ys - w1 * sum xs) / m | |
| m = fromIntegral (length vs) | |
| xs = map fst vs | |
| ys = map snd vs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment