當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。