擅长:python、mysql、java
<p>如注释中所建议的,通过向<code>statsmodels</code>函数提供<code>unbiased=True</code>,可以减少但不能完全解决问题。使用随机输入:</p>
<pre><code>import statistics
import numpy as np
import pandas as pd
from statsmodels.tsa.stattools import acf
DATA_LEN = 100
N_TESTS = 100
N_LAGS = 32
def test(unbiased):
data = pd.Series(np.random.random(DATA_LEN))
data_acf_1 = acf(data, unbiased=unbiased, nlags=N_LAGS)
data_acf_2 = [data.autocorr(i) for i in range(N_LAGS+1)]
# return difference between results
return sum(abs(data_acf_1 - data_acf_2))
for value in (False, True):
diffs = [test(value) for _ in range(N_TESTS)]
print(value, statistics.mean(diffs))
</code></pre>
<p>输出:</p>
<pre><code>False 0.464562410987
True 0.0820847168593
</code></pre>