## spe_eddy

Sorry - I know this isn't strictly Python, and i'm more asking for a formula than code!
Usually Excel functions show how they are calculated but i can't find anything on this one!
So given a set of data, predict what the next value will be based on the previous values
Thanks

## nezachem 616

Excel statistical functions: TREND

The TREND(known_y's, known_x's, new_x's, constant) function is used to perform Linear Regression. A least squares criterion is used and TREND tries to find the best fit under that criterion.

Is that what you are looking for?

## spe_eddy

not sure - Is that the definition from Excel?
So trend just uses the least squares criterion?

## griswolf 304

No. It uses linear regression which (waving my hands broadly) amounts to finding the 'best possible' line through a set of points, and, given N-1 coordinates for a new point, guessing that the other coordinate puts the point on that line. With error bars. Least squares is a good but not unique way to decide where that 'best possible' line lies.

¿Shouldn't this thread be in the Computer Science forum?

## spe_eddy

Ok thanks, would you rec recommend any other methods or do you think i should use least squares?
And yes it probably should be in Computer Science, sorry

## griswolf 304

Least squares has several things going for it:

• It is very common, so there are many examples, code snippets, etc
• It is well behaved
• It is reasonably simple

Unless I had a reason to suppose something else would be better, I'd default to least squares fitting.

Warning: All these things work, if at all, only on 'good' data. Statistics and various curve fitting techniques are prime candidates for GIGO problems.

## spe_eddy

Thanks very much,
do you know how i'd find the best fit line in Python though? Is it easily writeable?
My variable are independent of each other though - i am trying to predict the mean temperature of a day given the previous days' mean temperature, so the day is irrelevant - it's only the previous temperatures i'm concerned with.