Skip to content

Instantly share code, notes, and snippets.

@timjb
Created October 28, 2011 17:39
Show Gist options
  • Select an option

  • Save timjb/1322849 to your computer and use it in GitHub Desktop.

Select an option

Save timjb/1322849 to your computer and use it in GitHub Desktop.
AI class: Linear Regression
-- 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