Approximating a quadratic regression

Given a collection of points, this recipe will try to find a best fit quadratic equation. In the following figure, the curve is a best fit quadratic regression of the points:

Approximating a quadratic regression

Getting ready

Install the dsp package to use Matrix.LU as follows:

$ cabal install dsp

In order to perform a quadratic regression, we will use the least square polynomial fitting algorithm described in Wolfram MathWorld available at http://mathworld.wolfram.com/LeastSquaresFittingPolynomial.html.

How to do it…

  1. Import the following packages:
    import Data.Array (listArray, elems)
    import Matrix.LU (solve)
  2. Implement the quadratic regression algorithm, ...

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.