Beispiel #1
0
def test_plot_quarter():
    dta = sm.datasets.macrodata.load_pandas().data
    dates = lmap('Q'.join, zip(dta.year.astype(int).apply(str),
                              dta.quarter.astype(int).apply(str)))
    # test dates argument
    quarter_plot(dta.unemp.values, dates)
    plt.close('all')

    # test with a DatetimeIndex with no freq
    parser = pd.tseries.tools.parse_time_string
    dta.set_index(pd.DatetimeIndex((x[0] for x in map(parser, dates))),
                  inplace=True)
    quarter_plot(dta.unemp)
    plt.close('all')

    # w freq
    # see pandas #6631
    dta.index = pd.DatetimeIndex((x[0] for x in map(parser, dates)),
                                   freq='QS-Oct')
    quarter_plot(dta.unemp)
    plt.close('all')

    # w PeriodIndex
    dta.index = pd.PeriodIndex((x[0] for x in map(parser, dates)),
                                   freq='Q')
    quarter_plot(dta.unemp)
    plt.close('all')
Beispiel #2
0
def test_plot_quarter():
    dta = sm.datasets.macrodata.load_pandas().data
    dates = lmap(
        'Q'.join,
        zip(
            dta.year.astype(int).apply(str),
            dta.quarter.astype(int).apply(str)))
    # test dates argument
    quarter_plot(dta.unemp.values, dates)
    plt.close('all')

    # test with a DatetimeIndex with no freq
    parser = pd.datetools.parse_time_string
    dta.set_index(pd.DatetimeIndex((x[0] for x in map(parser, dates))),
                  inplace=True)
    quarter_plot(dta.unemp)
    plt.close('all')

    # w freq
    # see pandas #6631
    dta.index = pd.DatetimeIndex((x[0] for x in map(parser, dates)),
                                 freq='QS-Oct')
    quarter_plot(dta.unemp)
    plt.close('all')

    # w PeriodIndex
    dta.index = pd.PeriodIndex((x[0] for x in map(parser, dates)), freq='Q')
    quarter_plot(dta.unemp)
    plt.close('all')
Beispiel #3
0
def test_plot_quarter(close_figures):
    dta = sm.datasets.macrodata.load_pandas().data
    dates = lmap('Q'.join, zip(dta.year.astype(int).apply(str),
                               dta.quarter.astype(int).apply(str)))
    # test dates argument
    quarter_plot(dta.unemp.values, dates)

    # test with a DatetimeIndex with no freq
    dta.set_index(pd.to_datetime(dates), inplace=True)
    quarter_plot(dta.unemp)

    # w freq
    # see pandas #6631
    dta.index = pd.DatetimeIndex(pd.to_datetime(dates), freq='QS-Oct')
    quarter_plot(dta.unemp)

    # w PeriodIndex
    dta.index = pd.PeriodIndex(pd.to_datetime(dates), freq='Q')
    quarter_plot(dta.unemp)
Beispiel #4
0
def test_plot_quarter(close_figures):
    dta = sm.datasets.macrodata.load_pandas().data
    dates = lmap('Q'.join, zip(dta.year.astype(int).apply(str),
                               dta.quarter.astype(int).apply(str)))
    # test dates argument
    quarter_plot(dta.unemp.values, dates)

    # test with a DatetimeIndex with no freq
    dta.set_index(pd.to_datetime(dates), inplace=True)
    quarter_plot(dta.unemp)

    # w freq
    # see pandas #6631
    dta.index = pd.DatetimeIndex(pd.to_datetime(dates), freq='QS-Oct')
    quarter_plot(dta.unemp)

    # w PeriodIndex
    dta.index = pd.PeriodIndex(pd.to_datetime(dates), freq='Q')
    quarter_plot(dta.unemp)
Beispiel #5
0
from statsmodels.tsa.stattools import grangercausalitytests

grangercausalitytests(df3[['a', 'd']], maxlag=5)
grangercausalitytests(df3[['b', 'd']], maxlag=5)

np.random.seed(42)

df = pd.DataFrame(np.random.randint(20, 30, (50, 2)),
                  columns=['test', 'predictions'])

df.head()

df.plot(figsize=(12, 8))

from statsmodels.tools.eval_measures import mse, rmse, meanabs

mse(df['test'], df['predictions'])
rmse(df['test'], df['predictions'])
meanabs(df['test'], df['predictions'])

df1.head()
df1.index

from statsmodels.graphics.tsaplots import month_plot, quarter_plot

month_plot(df1['Pass_K'])

df1q = df1['Pass_K'].resample(rule='Q').sum()
quarter_plot(df1q)
Beispiel #6
0
        print("Weak evidence against the null hypothesis - do not reject")
        print("Data is NON-stationary")
    
    print('*******************************')
# --- |||

# now run the test on the specific series 
adf_run1 = adf_test(df1['Thousands of Passengers'])
print(adf_run1)

adf_run2 = adf_test(df2['Births'])
print(adf_run2)


#Granger causality test

#load a new dataset
df3 = pd.read_csv('data/samples.csv', index_col=0, parse_dates=True)
df3.index.freq='MS'

# run the test after inputing a guessed maxlag
granger1 = grangercausalitytests(df3[['a', 'd']], maxlag=2)


# seasonality check
month_plot(df1['Thousands of Passengers'])
#if we have quarterly data, we can resample the data
quarterly_data = df1['Thousands of Passengers'].resample(rule='Q').mean()
quarter_plot(quarterly_data)
# plt.show()
def plot_quarter(series, label=''):
    quarter_plot(series)
    # plt.title(label + ' Seasonal Subseries Plot')
    plt.title('')
    plt.xlabel('Quarter')
    plt.ylabel(label)
from statsmodels.tools.eval_measures import mse, rmse, meanabs

mse(df['test'],df['predictions']) #: 17.02

df4 = pd.read_csv('airline_passengers.csv', index_col = 'Month',parse_dates= True )

df4.index.freq = 'MS' 

from statsmodels.graphics.tsaplots import month_plot, quarter_plot

month_plot(df4['Thousands of Passengers']);


dfq = df4['Thousands of Passengers'].resample(rule = 'Q').mean()

quarter_plot(dfq)






 

dfout = pd.Series(dftest[0:4], index =['ADF Test Statisctics','p-value','#lags used','# Observations'] )
                  
                  
for key, val in dftest[4].items():
    dfout[f'critical value ({key})'] = val

dftest1 = adfuller(df2['Births'])