Talk:Polynomial regression

which norm to be used?

In which norm the approximation has to be done? Euclidean? C-norm? The basis seem to be xn? --Dmitry-kazakov 14:10, 4 June 2008 (MDT)

Any norm could be used. The task is not about mathematics. This task is intended as a subtask. The produced polynoms are used as labels for simple charts, therefore any norm will suffice. You may create a new task if a more formal task statement is desirable. The basis is 1, x, x2, x3, ..., xn. `n' is supposed to be known. -- Geka Sua 08:04, 7 June 2008 (MDT)

About fortran

It is quickly coded, and while trying to remember things. It works anyway, but I suppose there's a better way. the method I've followed is straightforwardly from --ShinTakezou 23:58, 18 December 2008 (UTC)

Good work with the Fortran routine. However, the scaling of the independent variable is missing without which the fitting will fail in many cases. For this purpose one needs the mean and standard deviation of the independent variable (vx in the code). Now scale vx to vxcopy and do everything using vxcopy. The code should be changed as follows. I am using this modified version for big applications in my work.

   allocate(XT(n, size(vx)))
   allocate(X(size(vx), n))
   allocate(XTX(n, n))

   vxcopy = vx                          !=== make a copy of the independent variable
   mu = stdmean(size(vxcopy), vxcopy)   !=== call the function stdmean and get mu(1) - mean, mu(2) - standard deviation
   vxcopy = (vxcopy - mu(1)) / mu(2)    !=== scale the coordinates 
   ! prepare the matrix
   do i = 0, d
      do j = 1, size(vx)
         X(j, i+1) = vxcopy(j)**i        !=== do the rest with vxcopy
      end do
   end do

--Raghu 12:31, 12 July 2011 (UTC)

Fortran matmul use

I am re working the Fortran example to use in a Delphi project.

The matrix multiply at the end of the example looks to be in the incorrect order.

I believe it should be.

polyfit = matmul( XTX, matmul(XT, vy))

I would appreciate if somebody with the Fortran language available could confirm.

The matrix product is associative, so mathematically there is no difference. Computationally, however, there is one, explained at Matrix chain multiplication. Eoraptor (talk) 16:33, 13 August 2020 (UTC)


Where can I read what call DGETRF(n, n, XTX, lda, ipiv, info) call DGETRI(n, XTX, lda, ipiv, work, lwork, info) do? ..Walterpachl (talk) 18:13, 18 December 2016 (UTC)

In LAPACK's documentation. Eoraptor (talk) 16:27, 13 August 2020 (UTC)

Not what I expected

Adding here in case others get confused as I did...

I was expecting this code to generate a polynomial that matched to a series of x,y points, so that I could then use that formula to extrapolate. However, it seems that all the coefficients are sensitive to the absolute magnitude of the x values. :( For example, if I change the original data x values from 0-11 to 1000-1011 I get the answer y = 2998001 - 5998*x - 0.036*x*x

I was expecting that it would change the first coefficient, but this is clearly a completely differently shaped parabola from y = 1 + 2x +3x*x

Fortunately, my data is a time series and in order, so I can subtract the initial x value from all the following x values.

Return to "Polynomial regression" page.