Python- doing least square fitting on time series data?
<p>I have a time series dataset pr11 (shape is (151,)) which looks like the graph below when plotted. Note the very small numbers. I want to find the average slope of the data by doing a least square fit to a straight line.</p>

<p><a href="https://i.stack.imgur.com/aGRlo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aGRlo.png" alt="Time series of precipitation from model"></a></p>

<p>I've tried two different methods from another StackExchange page to get the answer. I tried using scipy.optimize.curve_fit as below...</p>

<pre><code>len = np.arange(pr11.shape[0])

def f(x, A, B):
return A*x + B

A,B = curve_fit(f,pr11,len)[0]
</code></pre>

<p>However, this gives me a slope (A) of 1.0, which I know isn't right, so something must be off here. The "fitted" data just ends up looking the exact same as my original data. I also tried scipy.stats...</p>

<pre><code>slope, intercept, r_value, p_value, std_err = stats.linregress(len,pr11)
</code></pre>

<p>My slope this time is a number on the order of e-08. The issue with that is when I use the equation for a line slope*x + intercept, that number multiplies my time series data to a very low value (order e-15). Therefore when I plot the fitted line, the line is horizontal and doesn't fit my data at all.</p>

<p>How can I get a a fitted line for this data?</p>