当前位置: 首页>>代码示例>>Python>>正文


Python stattools.acf方法代码示例

本文整理汇总了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} 
开发者ID:quatrope,项目名称:feets,代码行数:23,代码来源:ext_autocor_length.py

示例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) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:27,代码来源:ACF.py

示例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 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:19,代码来源:ACF.py

示例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 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:test_tsa_tools.py

示例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) 
开发者ID:alkaline-ml,项目名称:pmdarima,代码行数:7,代码来源:wrapped.py

示例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] 
开发者ID:h2oai,项目名称:driverlessai-recipes,代码行数:16,代码来源:signal_processing.py

示例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()) 
开发者ID:mcleonard,项目名称:sampyl,代码行数:6,代码来源:diagnostics.py

示例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] 
开发者ID:esvhd,项目名称:pypbo,代码行数:28,代码来源:metrics.py

示例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() 
开发者ID:alan-turing-institute,项目名称:sktime,代码行数:6,代码来源:basic_benchmarking.py

示例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) 
开发者ID:alan-turing-institute,项目名称:sktime,代码行数:28,代码来源:basic_benchmarking.py

示例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 
开发者ID:isadoranun,项目名称:FATS,代码行数:16,代码来源:FeatureFunctionLib.py

示例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 
开发者ID:alan-turing-institute,项目名称:sktime,代码行数:44,代码来源:seasonality.py

示例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') 
开发者ID:alan-turing-institute,项目名称:sktime,代码行数:46,代码来源:experiments.py


注:本文中的statsmodels.tsa.stattools.acf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。