Re: Non-linear regression help in Python

Discussion in 'Python' started by sturlamolden, Feb 14, 2011.

  1. sturlamolden

    sturlamolden Guest

    On 14 Feb, 22:02, Akand Islam <> wrote:
    > Hello all,
    > I want to do non-linear regression by fitting the model (let say, y =
    > a1*x+b1*x**2+c1*x**3/exp(d1*x**4)) where the parameter (say "c1") must
    > be in between (0 to 1), and others can be of any values. How can I
    > perform my job in python?


    First, install NumPy and SciPy!

    scipy.optimize.leastsq implements Levenberg-Marquardt, which is close
    to the 'gold standard' for non-linear least squares. The algorithm
    will be a bit faster and more accurate if you provide the Jacobian of
    the residuals, i.e. the partial derivative of

    r = y - a1*x+b1*x**2+c1*x**3/exp(d1*x**4)

    with respect to a1, b1, c1, and d1 (stored in a 4 by n matrix).

    If you have prior information about c1, you have a Bayesian regression
    problem. You can constrain c1 between 1 and 0 by assuming a beta prior
    distribution on c1, e.g.

    c1 ~ Be(z,z) with 1 < z < 2

    Then proceed as you would with Bayesian regession -- i.e. EM, Gibbs'
    sampler, or Metropolis-Hastings. Use scipy.stats.beta to evaluate and
    numpy.random.beta to sample the beta distribution. The problem is not
    programming it in Python, but getting the correct equations on paper.
    Also beware that running the Markov chain Monte Carlo might take a
    while.

    Sturla
    sturlamolden, Feb 14, 2011
    #1
    1. Advertising

  2. sturlamolden

    sturlamolden Guest

    On 15 Feb, 05:24, Akand Islam <> wrote:

    > Dear Sturlamolden,
    > Thanks for reply. I will follow-up if I need further assistance.
    >
    > -- Akand


    You should rather use the SciPy user mailing list than
    comp.lang.python for this.

    Sturla
    sturlamolden, Feb 15, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nikie

    Linear regression in NumPy

    nikie, Mar 17, 2006, in forum: Python
    Replies:
    15
    Views:
    13,621
    nikie
    Mar 24, 2006
  2. Replies:
    1
    Views:
    389
    John Machin
    Sep 2, 2006
  3. Robert Kern

    Re: Linear regression in 3 dimensions

    Robert Kern, Sep 2, 2006, in forum: Python
    Replies:
    5
    Views:
    2,277
    David J. Braden
    Sep 15, 2006
  4. Nod Lee

    linear regression in webform

    Nod Lee, Jan 9, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    335
    Cowboy \(Gregory A. Beamer\)
    Jan 9, 2007
  5. Krzysztof Bieniasz

    Re: Non-linear regression help in Python

    Krzysztof Bieniasz, Feb 14, 2011, in forum: Python
    Replies:
    0
    Views:
    578
    Krzysztof Bieniasz
    Feb 14, 2011
Loading...

Share This Page