本文整理汇总了Python中statsmodels.tsa.stattools.acf函数的典型用法代码示例。如果您正苦于以下问题:Python acf函数的具体用法?Python acf怎么用?Python acf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了acf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
self.x = np.concatenate((np.array([np.nan]), self.x))
self.acf = self.results["acvar"] # drop and conservative
self.qstat = self.results["Q1"]
self.res_drop = acf(self.x, nlags=40, qstat=True, alpha=0.05, missing="drop")
self.res_conservative = acf(self.x, nlags=40, qstat=True, alpha=0.05, missing="conservative")
self.acf_none = np.empty(40) * np.nan # lags 1 to 40 inclusive
self.qstat_none = np.empty(40) * np.nan
self.res_none = acf(self.x, nlags=40, qstat=True, alpha=0.05, missing="none")
开发者ID:statsmodels,项目名称:statsmodels,代码行数:9,代码来源:test_stattools.py
示例2: setup_class
def setup_class(cls):
cls.x = np.concatenate((np.array([np.nan]),cls.x))
cls.acf = cls.results['acvar'] # drop and conservative
cls.qstat = cls.results['Q1']
cls.res_drop = acf(cls.x, nlags=40, qstat=True, alpha=.05,
missing='drop')
cls.res_conservative = acf(cls.x, nlags=40, qstat=True, alpha=.05,
missing='conservative')
cls.acf_none = np.empty(40) * np.nan # lags 1 to 40 inclusive
cls.qstat_none = np.empty(40) * np.nan
cls.res_none = acf(cls.x, nlags=40, qstat=True, alpha=.05,
missing='none')
开发者ID:eph,项目名称:statsmodels,代码行数:12,代码来源:test_stattools.py
示例3: __init__
def __init__(self):
self.x = np.concatenate((np.array([np.nan]),self.x))
self.acf = self.results['acvar'] # drop and conservative
self.qstat = self.results['Q1']
self.res_drop = acf(self.x, nlags=40, qstat=True, alpha=.05,
missing='drop')
self.res_conservative = acf(self.x, nlags=40, qstat=True, alpha=.05,
missing='conservative')
self.acf_none = np.empty(40) * np.nan # lags 1 to 40 inclusive
self.qstat_none = np.empty(40) * np.nan
self.res_none = acf(self.x, nlags=40, qstat=True, alpha=.05,
missing='none')
开发者ID:joesnacks,项目名称:statsmodels,代码行数:12,代码来源:test_stattools.py
示例4: SlowDecay
def SlowDecay():
r = abs(np.sum(df.replace(np.inf, np.nan).replace(-np.inf, np.nan).fillna(0), axis=1) / len(df.columns))
r = abs(df['AAPL'].replace(np.inf, np.nan).replace(-np.inf, np.nan).dropna(0))[:1000000]
r1 = (np.sum(df.replace(np.inf, np.nan).replace(-np.inf, np.nan).fillna(0), axis=1) / len(df.columns))
r1 = (df['AAPL'].replace(np.inf, np.nan).replace(-np.inf, np.nan).dropna(0))
acf1, conf = acf(pd.DataFrame(r), alpha=0.05, nlags=20)
acf2, conf2 = acf(pd.DataFrame(r1), alpha=0.05, nlags=20)
plt.plot(acf1, label='ACF Absolute Returns')
plt.plot(acf2, label='ACF Returns')
plt.fill_between(range(len(acf1)), [i[0] for i in conf], [i[1] for i in conf], alpha=0.3)
plt.fill_between(range(len(acf1)), [i[0] for i in conf2], [i[1] for i in conf2], alpha=0.3)
plt.legend(loc='best')
plt.savefig('Graphs/PACFAbsReturns.pdf', bbox_inches='tight')
开发者ID:Kristian60,项目名称:NetworkRisk,代码行数:13,代码来源:theoreticalfigures.py
示例5: fit
def fit(self, data):
magnitude = data[0]
AC = stattools.acf(magnitude, nlags=self.nlags)
k = next((index for index, value in
enumerate(AC) if value < np.exp(-1)), None)
while k is None:
self.nlags = self.nlags + 100
AC = stattools.acf(magnitude, nlags=self.nlags)
k = next((index for index, value in
enumerate(AC) if value < np.exp(-1)), None)
return k
开发者ID:npcastro,项目名称:FATS,代码行数:14,代码来源:FeatureFunctionLib.py
示例6: plot_acf
def plot_acf(data):
nlags = 90
lw = 2
x = range(nlags+1)
plt.figure(figsize=(6, 4))
plt.plot(x, acf(data['VIX']**2, nlags=nlags), lw=lw, label='VIX')
plt.plot(x, acf(data['RV']**2, nlags=nlags), lw=lw, label='RV')
plt.plot(x, acf(data['logR'], nlags=nlags), lw=lw, label='logR')
plt.legend()
plt.xlabel('Lags, days')
plt.grid()
plt.savefig('../plots/autocorr_logr_vix_rv.eps',
bbox_inches='tight', pad_inches=.05)
plt.show()
开发者ID:khrapovs,项目名称:datastorage,代码行数:15,代码来源:plot_spx_rv_vix.py
示例7: calc_autocorr
def calc_autocorr(self):
'''
Calculate the autocorrelation of an array.
'''
nlags = int(self.fs / self._minfreq)
self.acorr = acf(self._windowed(self.s2), nlags=nlags)
self.acorr_freq = self.fs / np.arange(self.acorr.size)
开发者ID:r-b-g-b,项目名称:AY250_HW,代码行数:7,代码来源:pitchDetect.py
示例8: PrintSerialCorrelations
def PrintSerialCorrelations(dailies):
"""Prints a table of correlations with different lags.
dailies: map from category name to DataFrame of daily prices
"""
filled_dailies = {}
for name, daily in dailies.items():
filled_dailies[name] = FillMissing(daily, span=30)
# print serial correlations for raw price data
for name, filled in filled_dailies.items():
corr = thinkstats2.SerialCorr(filled.ppg, lag=1)
print(name, corr)
rows = []
for lag in [1, 7, 30, 365]:
row = [str(lag)]
for name, filled in filled_dailies.items():
corr = thinkstats2.SerialCorr(filled.resid, lag)
row.append('%.2g' % corr)
rows.append(row)
print(r'\begin{tabular}{|c|c|c|c|}')
print(r'\hline')
print(r'lag & high & medium & low \\ \hline')
for row in rows:
print(' & '.join(row) + r' \\')
print(r'\hline')
print(r'\end{tabular}')
filled = filled_dailies['high']
acf = smtsa.acf(filled.resid, nlags=365, unbiased=True)
print('%0.3f, %0.3f, %0.3f, %0.3f, %0.3f' %
(acf[0], acf[1], acf[7], acf[30], acf[365]))
开发者ID:1000j,项目名称:ThinkStats2,代码行数:34,代码来源:timeseries.py
示例9: plot_acf_multiple
def plot_acf_multiple(ys, lags=20):
"""
"""
from statsmodels.tsa.stattools import acf
# hack
old_size = mpl.rcParams['font.size']
mpl.rcParams['font.size'] = 8
plt.figure(figsize=(10, 10))
xs = np.arange(lags + 1)
acorr = np.apply_along_axis(lambda x: acf(x, nlags=lags), 0, ys)
k = acorr.shape[1]
for i in range(k):
ax = plt.subplot(k, 1, i + 1)
ax.vlines(xs, [0], acorr[:, i])
ax.axhline(0, color='k')
ax.set_ylim([-1, 1])
# hack?
ax.set_xlim([-1, xs[-1] + 1])
mpl.rcParams['font.size'] = old_size
开发者ID:bert9bert,项目名称:statsmodels,代码行数:26,代码来源:ex_pandas.py
示例10: SimulateAutocorrelation
def SimulateAutocorrelation(daily, iters=1001, nlags=40):
"""Resample residuals, compute autocorrelation, and plot percentiles.
daily:
iters:
nlags:
"""
# run simulations
t = []
for i in range(iters):
filled = FillMissing(daily, span=30)
resid = thinkstats2.Resample(filled.resid)
acf = smtsa.acf(resid, nlags=nlags, unbiased=True)[1:]
t.append(np.abs(acf))
# put the results in an array and sort the columns
size = iters, len(acf)
array = np.zeros(size)
for i, acf in enumerate(t):
array[i,] = acf
array = np.sort(array, axis=0)
# find the bounds that cover 95% of the distribution
high = PercentileRow(array, 97.5)
low = -high
lags = range(1, nlags+1)
thinkplot.FillBetween(lags, low, high, alpha=0.2, color='gray')
开发者ID:aev3,项目名称:ThinkStats2,代码行数:27,代码来源:timeseries.py
示例11: acf_fcn
def acf_fcn(data,lags=2,alpha=.05):
#@FORMAT: data = np(values)
try:
acfvalues, confint,qstat,pvalues = acf(data,nlags=lags,qstat=True,alpha=alpha)
return [acfvalues,pvalues]
except:
return [np.nan]
开发者ID:tfz2101,项目名称:Machine-Learning,代码行数:7,代码来源:Signals_Testing.py
示例12: ACF_PACF_plot
def ACF_PACF_plot(self):
#plot ACF and PACF to find the number of terms needed for the AR and MA in ARIMA
# ACF finds MA(q): cut off after x lags
# and PACF finds AR (p): cut off after y lags
# in ARIMA(p,d,q)
lag_acf = acf(self.ts_log_diff, nlags=20)
lag_pacf = pacf(self.ts_log_diff, nlags=20, method='ols')
#Plot ACF:
ax=plt.subplot(121)
plt.plot(lag_acf)
ax.set_xlim([0,5])
plt.axhline(y=0,linestyle='--',color='gray')
plt.axhline(y= -1.96/np.sqrt(len(ts_log_diff)),linestyle='--',color='gray')
plt.axhline(y= 1.96/np.sqrt(len(ts_log_diff)),linestyle='--',color='gray')
plt.title('Autocorrelation Function')
#Plot PACF:
plt.subplot(122)
plt.plot(lag_pacf)
plt.axhline(y=0,linestyle='--',color='gray')
plt.axhline(y= -1.96/np.sqrt(len(ts_log_diff)),linestyle='--',color='gray')
plt.axhline(y=1.96/np.sqrt(len(ts_log_diff)),linestyle='--',color='gray')
plt.title('Partial Autocorrelation Function')
plt.tight_layout()
开发者ID:greatObelix,项目名称:datatoolbox,代码行数:25,代码来源:timeseries.py
示例13: setup_class
def setup_class(cls):
cls.acf = cls.results['acvar']
#cls.acf = np.concatenate(([1.], cls.acf))
cls.qstat = cls.results['Q1']
cls.res1 = acf(cls.x, nlags=40, qstat=True, alpha=.05)
cls.confint_res = cls.results[['acvar_lb','acvar_ub']].view((float,
2))
开发者ID:cong1989,项目名称:statsmodels,代码行数:7,代码来源:test_stattools.py
示例14: autocorrelation
def autocorrelation(x, *args, unbiased=True, nlags=None, fft=True, **kwargs):
"""
Return autocorrelation function of signal `x`.
Parameters
----------
x: array_like
A 1D signal.
nlags: int
The number of lags to calculate the correlation for (default .9*len(x))
fft: bool
Compute the ACF via FFT.
args, kwargs
As accepted by `statsmodels.tsa.stattools.acf`.
Returns
-------
acf: array
Autocorrelation function.
confint: array, optional
Confidence intervals if alpha kwarg provided.
"""
from statsmodels.tsa.stattools import acf
if nlags is None:
nlags = int(.9 * len(x))
corr = acf(x, *args, unbiased=unbiased, nlags=nlags, fft=fft, **kwargs)
return _significant_acf(corr, kwargs.get('alpha'))
开发者ID:e-hu,项目名称:orange3-timeseries,代码行数:27,代码来源:functions.py
示例15: lpc
def lpc(frame, order):
"""
frame: windowed signal
order: lpc order
return from 0th to `order`th linear predictive coefficients
"""
r = acf(frame, unbiased=False, nlags=order)
return levinson_durbin(r, order)[0]
开发者ID:shunsukeaihara,项目名称:pyssp,代码行数:8,代码来源:feature.py
示例16: __init__
def __init__(self):
self.acf = self.results['acvar']
#self.acf = np.concatenate(([1.], self.acf))
self.qstat = self.results['Q1']
self.res1 = acf(self.x, nlags=40, qstat=True, alpha=.05)
res = DataFrame.from_records(self.results)
self.confint_res = recarray_select(self.results, ['acvar_lb','acvar_ub'])
self.confint_res = self.confint_res.view((float, 2))
开发者ID:bert9bert,项目名称:statsmodels,代码行数:8,代码来源:test_stattools.py
示例17: plotACF
def plotACF(timeSeries):
lag_acf = acf(timeSeries, nlags=40)
plt.subplot(121)
plt.plot(lag_acf)
plt.axhline(y=0,linestyle='--',color='gray')
plt.axhline(y=-1.96/np.sqrt(len(timeSeries)),linestyle='--',color='gray')
plt.axhline(y=1.96/np.sqrt(len(timeSeries)),linestyle='--',color='gray')
plt.title('Autocorrelation Function')
开发者ID:sunny123123,项目名称:hadoop,代码行数:8,代码来源:ARIMAtest.py
示例18: correlation_plot
def correlation_plot(d, dt=6e-3, **kwargs):
corr, conf = acf(d, nlags=len(d)-1, alpha=0.05)
taus = dt*np.arange(0, len(d))
ax = pl.gca()
ax.plot(taus, corr, **kwargs)
ax.fill_between(taus, y1=conf[:,0], y2=conf[:,1], color='k', alpha=0.2, lw=0)
ax.set_xscale('log')
ax.set_xlabel(r'$\tau$ (seconds)')
ax.set_ylabel(r'$G(\tau)$')
ax.grid()
开发者ID:bgamari,项目名称:thesis-data,代码行数:10,代码来源:correlation.py
示例19: ljungBox2
def ljungBox2(x, maxlag):
lags = np.asarray(range(1, maxlag+1))
x = x.tolist()
n = len(x)
acfx = acf(x, nlags=maxlag) # normalize by nobs not (nobs-nlags)
acf2norm = acfx[1:maxlag+1]**2 / (n - np.arange(1,maxlag+1))
qljungbox = n * (n+2) * np.cumsum(acf2norm)[lags-1]
pval = scipy.stats.chi2.sf(qljungbox, lags)
return qljungbox, pval
开发者ID:ecsalina,项目名称:patient-portal,代码行数:10,代码来源:_math.py
示例20: get_acf_pacf
def get_acf_pacf(self, inputDataSeries, lag = 15):
# Copy the data in input data
outputData = pandas.DataFrame(inputDataSeries)
if min(inputDataSeries.index) == inputDataSeries.index[0]:
# Ascending
multiplier = 1
lag = multiplier*lag
elif max(inputDataSeries.index) == inputDataSeries.index[0]:
# Descending
multiplier = -1
lag = multiplier*lag
else:
print('Cannot determine the order put the lag value manually')
print('Syntax: calc_returns(inputData, columnName, lag = lag_value)')
n_iter = lag
columnName = outputData.columns[0]
i = 1
# Calculate ACF
acf_values = []
acf_values.append(outputData[columnName].corr(outputData[columnName]))
while i <= abs(n_iter):
col_name = 'lag_' + str(i)
outputData[col_name] = ''
outputData[col_name] = outputData[columnName].shift(multiplier*i)
i += 1
acf_values.append(outputData[columnName].corr(outputData[col_name]))
# Define an emplty figure
fig = plt.figure()
# Define 2 subplots
ax1 = fig.add_subplot(211) # 2 by 1 by 1 - 1st plot in 2 plots
ax2 = fig.add_subplot(212) # 2 by 1 by 2 - 2nd plot in 2 plots
ax1.plot(range(len(acf_values)), acf(inputDataSeries, nlags = n_iter), \
range(len(acf_values)), acf_values, 'ro')
ax2.plot(range(len(acf_values)), pacf(inputDataSeries, nlags = n_iter), 'g*-')
# Plot horizontal lines
ax1.axhline(y = 0.0, color = 'black')
ax2.axhline(y = 0.0, color = 'black')
# Axis labels
plt.xlabel = 'Lags'
plt.ylabel = 'Correlation Coefficient'
return {'acf' : list(acf_values), \
'pacf': pacf(inputDataSeries, nlags = n_iter)}
开发者ID:kshiitijee,项目名称:Time_Series,代码行数:54,代码来源:pandas_data_download.py
注:本文中的statsmodels.tsa.stattools.acf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论