[SciPy-user] Multivariate regression?
Ryan Krauss
ryanlists@gmail....
Fri Oct 5 16:10:02 CDT 2007
This may be unnecessarily complicated, but I almost always use fmin
where I have defined some squared error that I want to minimize. This
essentially lets you do an arbitrarily complicated expression.
To use it to do a linear regression, you would use a cost function like:
def myfunc(c):
model = c[0]*x+c[1]
error_squared = (model - y_exp)**2
return error_squared.sum()
where x and y_exp would have to be defined in the script before the
function is called.
c_final = optimize.fmin(myfunc, [m0, b0])
would then fit the data using m0 and b0 as initial guesses.
fmin essentially varies the parameters in the vector c until a minimum
of the returned value is found. You could use any model you wanted.
HTH,
Ryan
On 10/5/07, halish <mhaligowski@googlemail.com> wrote:
> Hello,
>
> in the first place, I'd like to say 'Hi' to all the subscribers, as
> this is my first mail.
>
> I study econometrics and statistics, and i wanted to try out my
> favourite programming as a scientific tool. Unfortunately, I could not
> find a function for ordinary least squares estimation. The
> stats.linregress() is insufficient for my needs, and stats.glm() seems
> to be for something else (not sure really).
>
> Would you guys suggest something? Or should I just write it on my own?
>
> Regards,
> halish
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
More information about the SciPy-user
mailing list