本文整理匯總了Python中statsmodels.tsa.stattools.acf方法的典型用法代碼示例。如果您正苦於以下問題:Python stattools.acf方法的具體用法?Python stattools.acf怎麽用?Python stattools.acf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類statsmodels.tsa.stattools
的用法示例。
在下文中一共展示了stattools.acf方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: fit
# 需要導入模塊: from statsmodels.tsa import stattools [as 別名]
# 或者: from statsmodels.tsa.stattools import acf [as 別名]
def fit(self, magnitude, nlags):
AC = stattools.acf(magnitude, nlags=nlags, fft=True)
k = next(
(index for index, value in enumerate(AC) if value < np.exp(-1)),
None,
)
while k is None:
nlags = nlags + 100
AC = stattools.acf(magnitude, nlags=nlags, fft=True)
k = next(
(
index
for index, value in enumerate(AC)
if value < np.exp(-1)
),
None,
)
return {"Autocor_length": k}
示例2: __init__
# 需要導入模塊: from statsmodels.tsa import stattools [as 別名]
# 或者: from statsmodels.tsa.stattools import acf [as 別名]
def __init__(self, options):
self.handle_options(options)
params = options.get('params', {})
converted_params = convert_params(
params,
ints=['k', 'conf_interval'],
bools=['fft'],
aliases={'k': 'nlags'},
)
# Set the default name to be used so that PACF can override
self.default_name = 'acf({})'
# Set the lags, alpha and fft parameters
self.nlags = converted_params.pop('nlags', 40)
self.fft = converted_params.pop('fft', False)
conf_int = converted_params.pop('conf_interval', 95)
if conf_int <= 0 or conf_int >= 100:
raise RuntimeError('conf_interval cannot be less than 1 or more than 99.')
if self.nlags <= 0:
raise RuntimeError('k must be greater than 0.')
self.alpha = confidence_interval_to_alpha(conf_int)
示例3: _calculate
# 需要導入模塊: from statsmodels.tsa import stattools [as 別名]
# 或者: from statsmodels.tsa.stattools import acf [as 別名]
def _calculate(self, df):
"""Calculate the ACF.
Args:
X (dataframe): input data
Returns:
autocors (array): array of autocorrelations
conf_int (array): array of confidence intervals
"""
autocors, conf_int = acf(
x=df.values,
nlags=self.nlags,
alpha=self.alpha,
fft=self.fft
)
return autocors, conf_int
示例4: test_acf
# 需要導入模塊: from statsmodels.tsa import stattools [as 別名]
# 或者: from statsmodels.tsa.stattools import acf [as 別名]
def test_acf():
acf_x = tsa.acf(x100, unbiased=False)[:21]
assert_array_almost_equal(mlacf.acf100.ravel(), acf_x, 8) # why only dec=8
acf_x = tsa.acf(x1000, unbiased=False)[:21]
assert_array_almost_equal(mlacf.acf1000.ravel(), acf_x, 8) # why only dec=9
示例5: acf
# 需要導入模塊: from statsmodels.tsa import stattools [as 別名]
# 或者: from statsmodels.tsa.stattools import acf [as 別名]
def acf(x, unbiased=False, nlags=40, qstat=False, fft=False,
alpha=None, missing='none'):
return sm_acf(x=x, unbiased=unbiased, nlags=nlags,
qstat=qstat, fft=fft, alpha=alpha,
missing=missing)
示例6: agg_autocorrelation
# 需要導入模塊: from statsmodels.tsa import stattools [as 別名]
# 或者: from statsmodels.tsa.stattools import acf [as 別名]
def agg_autocorrelation(x, param):
"""Credit goes to https://github.com/blue-yonder/tsfresh"""
# if the time series is longer than the following threshold, we use fft to calculate the acf
THRESHOLD_TO_USE_FFT = 1250
var = np.var(x)
n = len(x)
max_maxlag = max([config["maxlag"] for config in param])
if np.abs(var) < 10 ** -10 or n == 1:
a = [0] * len(x)
else:
a = acf(x, unbiased=True, fft=n > THRESHOLD_TO_USE_FFT, nlags=max_maxlag)[1:]
return [("f_agg_\"{}\"__maxlag_{}".format(config["f_agg"], config["maxlag"]),
getattr(np, config["f_agg"])(a[:int(config["maxlag"])])) for config in param]
示例7: compute_n_eff_acf
# 需要導入模塊: from statsmodels.tsa import stattools [as 別名]
# 或者: from statsmodels.tsa.stattools import acf [as 別名]
def compute_n_eff_acf(theta_chain):
""" computes autocorrelation based effective sample size"""
n = theta_chain.shape[0]
return n / (1. + 2 * stattools.acf(theta_chain)[1:].sum())
示例8: sharpe_autocorr_factor
# 需要導入模塊: from statsmodels.tsa import stattools [as 別名]
# 或者: from statsmodels.tsa.stattools import acf [as 別名]
def sharpe_autocorr_factor(returns, q):
"""
Auto-correlation correction for Sharpe ratio time aggregation based on
Andrew Lo's 2002 paper.
Link:
https://www.google.co.uk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwj5wf2OjO_OAhWDNxQKHT0wB3EQFggeMAA&url=http%3A%2F%2Fedge-fund.com%2FLo02.pdf&usg=AFQjCNHbSz0LDZxFXm6pmBQukCfAYd0K7w&sig2=zQgZAN22RQcQatyP68VKmQ
Parameters:
returns :
return sereis
q :
time aggregation factor, e.g. 12 for monthly to annual,
252 for daily to annual
Returns:
factor : time aggregation factor
p-value : p-value for Ljung-Box serial correation test.
"""
# Ljung-Box Null: data is independent, i.e. no auto-correlation.
# smaller p-value would reject the Null, i.e. there is auto-correlation
acf, _, pval = sts.acf(returns, unbiased=False, nlags=q, qstat=True)
term = [(q - (k + 1)) * acf[k + 1] for k in range(q - 2)]
factor = q / np.sqrt(q + 2 * np.sum(term))
return factor, pval[-2]
示例9: acf_coefs
# 需要導入模塊: from statsmodels.tsa import stattools [as 別名]
# 或者: from statsmodels.tsa.stattools import acf [as 別名]
def acf_coefs(x, maxlag=100):
x = np.asarray(x).ravel()
nlags = np.minimum(len(x) - 1, maxlag)
return acf(x, nlags=nlags).ravel()
示例10: rise_benchmarking
# 需要導入模塊: from statsmodels.tsa import stattools [as 別名]
# 或者: from statsmodels.tsa.stattools import acf [as 別名]
def rise_benchmarking():
for i in range(0, len(benchmark_datasets)):
dataset = benchmark_datasets[i]
print(str(i) + " problem = " + dataset)
rise = fb.RandomIntervalSpectralForest(n_estimators=100)
exp.run_experiment(overwrite=True, problem_path=data_dir,
results_path=results_dir, cls_name="PythonRISE",
classifier=rise, dataset=dataset, train_file=False)
steps = [
('segment', RandomIntervalSegmenter(n_intervals=1, min_length=5)),
('transform', FeatureUnion([
('acf', RowTransformer(
FunctionTransformer(func=acf_coefs, validate=False))),
('ps', RowTransformer(
FunctionTransformer(func=powerspectrum, validate=False)))
])),
('tabularise', Tabularizer()),
('clf', DecisionTreeClassifier())
]
base_estimator = Pipeline(steps)
rise = TimeSeriesForestClassifier(estimator=base_estimator,
n_estimators=100)
exp.run_experiment(overwrite=True, problem_path=data_dir,
results_path=results_dir,
cls_name="PythonRISEComposite",
classifier=rise, dataset=dataset, train_file=False)
示例11: fit
# 需要導入模塊: from statsmodels.tsa import stattools [as 別名]
# 或者: from statsmodels.tsa.stattools import acf [as 別名]
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
示例12: autocorrelation_seasonality_test
# 需要導入模塊: from statsmodels.tsa import stattools [as 別名]
# 或者: from statsmodels.tsa.stattools import acf [as 別名]
def autocorrelation_seasonality_test(y, sp):
"""Seasonality test used in M4 competition
Parameters
----------
sp : int
Seasonal periodicity
Returns
-------
is_seasonal : bool
Test result
References
----------
..[1] https://github.com/Mcompetitions/M4-methods/blob/master
/Benchmarks%20and%20Evaluation.R
"""
y = check_y(y)
sp = check_sp(sp)
y = np.asarray(y)
n_timepoints = len(y)
if sp == 1:
return False
if n_timepoints < 3 * sp:
warn(
"Did not perform seasonality test, as `y`` is too short for the "
"given `sp`, returned: False")
return False
else:
coefs = acf(y, nlags=sp, fft=False) # acf coefficients
coef = coefs[sp] # coefficient to check
tcrit = 1.645 # 90% confidence level
limits = tcrit / np.sqrt(n_timepoints) * np.sqrt(
np.cumsum(np.append(1, 2 * coefs[1:] ** 2)))
limit = limits[sp - 1] # zero-based indexing
return np.abs(coef) > limit
示例13: set_classifier
# 需要導入模塊: from statsmodels.tsa import stattools [as 別名]
# 或者: from statsmodels.tsa.stattools import acf [as 別名]
def set_classifier(cls, resampleId):
"""
Basic way of determining the classifier to build. To differentiate settings just and another elif. So, for example, if
you wanted tuned TSF, you just pass TuneTSF and set up the tuning mechanism in the elif.
This may well get superceded, it is just how e have always done it
:param cls: String indicating which classifier you want
:return: A classifier.
"""
if cls.lower() == 'pf':
return pf.ProximityForest(random_state = resampleId)
elif cls.lower() == 'pt':
return pf.ProximityTree(random_state = resampleId)
elif cls.lower() == 'ps':
return pf.ProximityStump(random_state = resampleId)
elif cls.lower() == 'rise':
return fb.RandomIntervalSpectralForest(random_state = resampleId)
elif cls.lower() == 'tsf':
return ib.TimeSeriesForest(random_state = resampleId)
elif cls.lower() == 'boss':
return db.BOSSEnsemble()
elif cls.lower() == 'st':
return st.ShapeletTransformClassifier(time_contract_in_mins=1500)
elif cls.lower() == 'dtwcv':
return nn.KNeighborsTimeSeriesClassifier(metric="dtwcv")
elif cls.lower() == 'ee' or cls.lower() == 'elasticensemble':
return dist.ElasticEnsemble()
elif cls.lower() == 'tsfcomposite':
#It defaults to TSF
return ensemble.TimeSeriesForestClassifier()
elif cls.lower() == 'risecomposite':
steps = [
('segment', RandomIntervalSegmenter(n_intervals=1, min_length=5)),
('transform', FeatureUnion([
('acf', RowTransformer(FunctionTransformer(func=acf_coefs, validate=False))),
('ps', RowTransformer(FunctionTransformer(func=powerspectrum, validate=False)))
])),
('tabularise', Tabularizer()),
('clf', DecisionTreeClassifier())
]
base_estimator = Pipeline(steps)
return ensemble.TimeSeriesForestClassifier(estimator=base_estimator, n_estimators=100)
else:
raise Exception('UNKNOWN CLASSIFIER')