Best fit program in Python

Chaotic42

Lifer
Jun 15, 2001
33,936
1,114
126
Hey folks.

I need an algorithm to determine the coordinates of a best fit plane in 3D space given data.

For example, if you're given 65 3D coordinates, I need to figure out what rectangular 2D plane will best fit that data. I've been looking around and haven't found anything yet, I figured I'd ask and see if anyone knows off hand.

Thanks.
 

UCJefe

Senior member
Jan 27, 2000
302
0
0
Disclaimer: I know next to nothing about Python. I'm a Perl/everything else guy. One of these days I'll learn Python, I swear

You'll want to do matrix left division using least-squares approximation. Basically you're solving the equation A*X = B where A is a m x 3 matrix consisting of your x, y, and const column vectors and B is a m-column vector consiting of your z points. The solution (X) will be your coefficients to your best-fit plane (z = ax + by + c). In Java, you use the solve() method on the Matrix class. You're probably going to have to do the math yourself in Python unless there's a math (package?) somewhere that does it for you. A quick search turned up a couple of possibilities.

ScientificPython

or

SciPy

I have no idea if that helps, but it's worth a look.
 

Chaotic42

Lifer
Jun 15, 2001
33,936
1,114
126
Hmm... Matrix stuff. I haven't done that yet in my studies.

Thanks for the post, I'm going to have to do some reasearch.