Skip to content

Instantly share code, notes, and snippets.

@gavinwhyte
Last active August 29, 2015 14:23
Show Gist options
  • Save gavinwhyte/d85b0ed8eb9a9f804cfd to your computer and use it in GitHub Desktop.
Save gavinwhyte/d85b0ed8eb9a9f804cfd to your computer and use it in GitHub Desktop.
Linear Regression
import Statistics.LinearRegression
import qualified Data.Vector.Unboxed as U
-- Computing a linear regression
main = do
let xs = U.fromList [1.0, 2.0, 3.0, 4.0, 5.0] :: U.Vector Double
let ys = U.fromList [1.0, 2.0, 1.3, 3.75, 2.25] :: U.Vector Double
let (b, m) = linearRegression xs ys
print $ concat ["y = ", show m, " x + ", show b]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment