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


Python stattools.pacf函数代码示例

本文整理汇总了Python中statsmodels.tsa.stattools.pacf函数的典型用法代码示例。如果您正苦于以下问题:Python pacf函数的具体用法?Python pacf怎么用?Python pacf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了pacf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ld

    def test_ld(self):
        pacfyw = pacf_yw(self.x, nlags=40, method="mle")
        pacfld = pacf(self.x, nlags=40, method="ldb")
        assert_almost_equal(pacfyw, pacfld, DECIMAL_8)

        pacfyw = pacf(self.x, nlags=40, method="yw")
        pacfld = pacf(self.x, nlags=40, method="ldu")
        assert_almost_equal(pacfyw, pacfld, DECIMAL_8)
开发者ID:joesnacks,项目名称:statsmodels,代码行数:8,代码来源:test_stattools.py

示例2: 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

示例3: test_ols

 def test_ols(self):
     pacfols, confint = pacf(self.x, nlags=40, alpha=.05, method="ols")
     assert_almost_equal(pacfols[1:], self.pacfols, DECIMAL_6)
     centered = confint - confint.mean(1)[:,None]
     # from edited Stata ado file
     res = [[-.1375625, .1375625]] * 40
     assert_almost_equal(centered[1:41], res, DECIMAL_6)
开发者ID:joesnacks,项目名称:statsmodels,代码行数:7,代码来源:test_stattools.py

示例4: 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

示例5: partial_autocorrelation

def partial_autocorrelation(x, *args, nlags=None, method='ldb', **kwargs):
    """
    Return partial autocorrelation function (PACF) of signal `x`.

    Parameters
    ----------
    x: array_like
        A 1D signal.
    nlags: int
        The number of lags to calculate the correlation for
        (default: min(600, len(x)))
    args, kwargs
        As accepted by `statsmodels.tsa.stattools.pacf`.

    Returns
    -------
    acf: array
        Partioal autocorrelation function.
    confint : optional
        As returned by `statsmodels.tsa.stattools.pacf`.
    """
    from statsmodels.tsa.stattools import pacf
    if nlags is None:
        nlags = min(1000, len(x) - 1)
    corr = pacf(x, *args, nlags=nlags, method=method, **kwargs)
    return _significant_acf(corr, kwargs.get('alpha'))
开发者ID:e-hu,项目名称:orange3-timeseries,代码行数:26,代码来源:functions.py

示例6: plotPACF

def plotPACF(timeSeries):
    lag_pacf = pacf(timeSeries, nlags=20, method='ols')
    plt.subplot(122)
    plt.plot(lag_pacf)
    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('Partial Autocorrelation Function')
    plt.tight_layout()
开发者ID:sunny123123,项目名称:hadoop,代码行数:9,代码来源:ARIMA_predict002.py

示例7: ARIMA_fun

def ARIMA_fun( data ):
    lag_pacf = pacf( data, nlags=20, method='ols' )
    lag_acf, ci2, Q  = acf( data, nlags=20 , qstat=True, unbiased=True)

    model = ARIMA(orig_data, order=(1, 1, int(ci2[0]) ) )  
    results_ARIMA = model.fit(disp=-1)
    plt.subplot(121)
    plt.plot( data )
    plt.plot(results_ARIMA.fittedvalues)
    #plt.show()
    return results_ARIMA.fittedvalues
开发者ID:s4hackathons,项目名称:singularity,代码行数:11,代码来源:arima.py

示例8: FE

    def FE(self, serie_atual):
        '''
        Método para fazer a diferenciacao de uma serie_atual
        :param serie_atual: serie_atual real
        '''  
        
        #serie_df = pd.DataFrame(serie_atual)
        serie_diff = pd.Series(serie_atual)
        serie_diff = serie_diff - serie_diff.shift()
        serie_diff = serie_diff[1:]
        
        
        features = []
        
        #feature 1:
        auto_correlacao = acf(serie_diff, nlags=5)
        for i in auto_correlacao:
            features.append(i)
        
        #feature 2:
        parcial_atcorr = pacf(serie_diff, nlags=5)
        for i in parcial_atcorr:
            features.append(i)
        
        #feature 3:
        variancia = serie_diff.std()
        features.append(variancia)
        
        #feature 4:
        serie_skew = serie_diff.skew()
        features.append(serie_skew)

        #feature 5:
        serie_kurtosis = serie_diff.kurtosis()
        features.append(serie_kurtosis)
        
        #feature 6:
        turning_p = self.turningpoints(serie_diff)
        features.append(turning_p)
        
        #feature 7:
        
        #feature 8:
        
        
        return features
开发者ID:GustavoHFMO,项目名称:Framework_drift,代码行数:46,代码来源:FEDD.py

示例9: global_analysis

def global_analysis(csv_fname, trajectory_df):
    # catch small trajectory_dfs
    if len(trajectory_df.index) < MIN_TRAJECTORY_LEN:
        return None
    else:
        
        # for each trajectory, loop through segments
        acf_data = np.zeros((len(INTERESTED_VALS), 1, LAGS+1))
        pacf_data = np.zeros((len(INTERESTED_VALS), 1, LAGS+1))
        
            
        # do analysis variable by variable
        count = -1
        for var_name, var_values in trajectory_df.iteritems():
            count += 1
            # make matrices
            
            
            
            # make dictionary for column indices
            var_index = trajectory_df.columns.get_loc(var_name)
#                {'velo_x':0, 'velo_y':1, 'velo_z':2, 'curve':3, 'log_curve':4}[var_name]
            
#            # run ACF and PACF for the column
            col_acf, acf_confint = acf(var_values, nlags=LAGS, alpha=.05)#,  qstat= True)
#            
#            # store data
            acf_data[var_index, 0, :] = col_acf
##            super_data_confint_lower[var_index, segment_i, :] = acf_confint[:,0]
##            super_data_confint_upper[var_index, segment_i, :] = acf_confint[:,1]
            
            
#            ## , acf_confint, acf_qstats, acf_pvals
            col_pacf, pacf_confint = pacf(var_values, nlags=LAGS, method='ywmle', alpha=.05)
            pacf_data[var_index, 0, :] = col_pacf
#            # TODO: check for PACF values above or below +-1
#            super_data[var_index+len(INTERESTED_VALS), segment_i, :] = col_pacf
#            super_data_confint_lower[var_index+len(INTERESTED_VALS), segment_i, :] = pacf_confint[:,0]
#            super_data_confint_upper[var_index+len(INTERESTED_VALS), segment_i, :] = pacf_confint[:,1]

                
                
            
        
        return acf_data, pacf_data
开发者ID:isomerase,项目名称:RoboSkeeter,代码行数:45,代码来源:correlation_matrices.py

示例10: 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
     
     return {'acf' : acf(inputDataSeries, nlags = n_iter), \
             'pacf': pacf(inputDataSeries, nlags = n_iter)} 
开发者ID:kshiitijee,项目名称:Time_Series,代码行数:20,代码来源:pandas_data_download.py

示例11: corrfunc

def corrfunc(timeseries):
	diff_ts = timeseries - timeseries.shift()
	diff_ts.dropna(inplace=True)
	ts_acf = acf(diff_ts, nlags=20)
	ts_pacf = pacf(diff_ts, nlags=20, method='ols')
	#Plot ACF and PACF:
	fig = plt.figure(figsize=(12,8))
	ax1 = fig.add_subplot(211)
	plt.tick_params(axis="both", which="both", bottom="on", top="off",    
		                labelbottom="on", left="on", right="off", labelleft="on")
	fig = sm.graphics.tsa.plot_acf(timeseries.values.squeeze(), lags=20, ax=ax1)
	plt.title('ACF', fontsize=15)
	ax2 = fig.add_subplot(212)
	fig = sm.graphics.tsa.plot_pacf(timeseries, lags=20, ax=ax2)
	plt.tick_params(axis="both", which="both", bottom="on", top="off",    
		                labelbottom="on", left="on", right="off", labelleft="on")
	plt.xlabel("Lags", fontsize=14) 
	plt.title('PACF', fontsize=15)
	plt.tight_layout()
	fig.savefig('corrfunc.png', bbox_inches="tight")
开发者ID:mkgunasinghe,项目名称:examples,代码行数:20,代码来源:timeseries.py

示例12: plot_acf_and_pacf

def plot_acf_and_pacf(y):
    lag_acf = acf(y, nlags=20)
    lag_pacf = pacf(y, nlags=20, method='ols')
    
    plt.subplot(121) 
    plt.plot(lag_acf)
    plt.axhline(y=0,linestyle='--',color='gray')
    plt.axhline(y=-1.96/np.sqrt(len(y)),linestyle='--',color='gray')
    plt.axhline(y=1.96/np.sqrt(len(y)),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(y)),linestyle='--',color='gray')
    plt.axhline(y=1.96/np.sqrt(len(y)),linestyle='--',color='gray')
    plt.title('Partial Autocorrelation Function')
    plt.tight_layout()
    plt.show()
    plt.close()
开发者ID:MBleeker,项目名称:Data-Mining,代码行数:21,代码来源:exploration-liam.py

示例13: acf_pacf

def acf_pacf(ts):
	ts_log, ts_log_diff = trend(ts)
	lag_acf = acf(ts_log_diff, nlags = 20)
	lag_pacf = pacf(ts_log_diff, nlags = 20, method = 'ols')

	#plot acf
	plt.subplot(121)
	plt.plot(lag_acf)
	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()
	plt.show()
开发者ID:pthaike,项目名称:comp,代码行数:23,代码来源:process.py

示例14: print

print(arma_res.summary())


# In[3]:


arma_res.resid.iloc[1:].plot(figsize=(6,4),color='seagreen')
plt.ylabel('$\hat{z_t}$')


# In[4]:


from statsmodels.tsa import stattools
acf,q,pvalue = stattools.acf(arma_res.resid,nlags=5,qstat=True)
pacf,confint = stattools.pacf(arma_res.resid,nlags=5,alpha=0.05)
print("自己相関係数:",acf)
print("p値:",pvalue)
print("偏自己相関:",pacf)
print("95%信頼区間:",confint)


# In[5]:


p=sm.tsa.adfuller(arma_res.resid,regression='nc')[1] #[1]はp値の検定結果
p1=sm.tsa.adfuller(arma_res.resid,regression='c')[1] #[1]はp値の検定結果
print("ドリフト無しランダムウォーク p値:",p)
print("ドリフト付きランダムウォーク p値:",p1)

开发者ID:jettom,项目名称:SoftArsenal,代码行数:29,代码来源:pan8.py

示例15: Series

# -*- coding: utf-8 -*-

import numpy as np
from pandas import *
from statsmodels.tsa import stattools
import matplotlib.pyplot as plt

randn = np.random.randn

ts = Series(randn(1000), index=DateRange('2000/1/1', periods=1000))
ts = ts.cumsum()

ts.plot(style='<--')
rolling_mean(ts, 60).plot(style='--', c='r')
rolling_mean(ts, 180).plot(style='--', c='b')

acf = stattools.acf(np.array(ts), 50)
plt.bar(range(len(acf)), acf, width=0.01)
plt.savefig("image.png")

pcf = stattools.pacf(np.array(ts), 50)
plt.bar(range(len(pcf)), pcf, width=0.01)
plt.show()
plt.savefig("image2.png")
开发者ID:id774,项目名称:sandbox,代码行数:24,代码来源:random-walk.py


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