Approximating a linear regression

Given a list of points, we can estimate the best fit line using a handy library, Statistics.LinearRegression.

It computes the least square difference between points to estimate the best fit line. An example of a linear regression of points can be seen in the following figure:

Approximating a linear regression

A best-fit line is drawn through five points using linear regression

Getting ready

Install the appropriate library using cabal as follows:

$ cabal install statistics-linreg

How to do it…

  1. Import the following packages:
    import Statistics.LinearRegression
    import qualified Data.Vector.Unboxed as U
  2. Create a series of points from their coordinates, and ...

Get Haskell Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.