Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Non-linear regression help in Python

Reply
Thread Tools

Re: Non-linear regression help in Python

 
 
sturlamolden
Guest
Posts: n/a
 
      02-14-2011
On 14 Feb, 22:02, Akand Islam <sohel...@gmail.com> 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
 
Reply With Quote
 
 
 
 
sturlamolden
Guest
Posts: n/a
 
      02-15-2011
On 15 Feb, 05:24, Akand Islam <sohel...@gmail.com> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python install regression test fail John Nagle Python 0 12-17-2011 07:24 PM
Re: Non-linear regression help in Python Krzysztof Bieniasz Python 0 02-14-2011 09:24 PM
Regression testing with Python Almad Python 0 06-05-2007 09:44 AM
Latent class regression in Java? Craig Matthews Java 2 07-26-2003 12:41 AM
exp regression? jackson marshmallow Java 4 07-19-2003 10:20 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57