Пример #1
0
def test_plot_month():
    dta = sm.datasets.elnino.load_pandas().data
    dta['YEAR'] = dta.YEAR.astype(int).apply(str)
    dta = dta.set_index('YEAR').T.unstack()
    dates = lmap(lambda x: pd.tseries.tools.parse_time_string('1 '+' '.join(x))[0],
                 dta.index.values)

    # test dates argument
    fig = month_plot(dta.values, dates=dates, ylabel='el nino')
    plt.close(fig)

    # test with a TimeSeries DatetimeIndex with no freq
    dta.index = pd.DatetimeIndex(dates)
    fig = month_plot(dta)
    plt.close(fig)

    # w freq
    dta.index = pd.DatetimeIndex(dates, freq='MS')
    fig = month_plot(dta)
    plt.close(fig)

    # test with a TimeSeries PeriodIndex
    dta.index = pd.PeriodIndex(dates, freq='M')
    fig = month_plot(dta)
    plt.close(fig)
Пример #2
0
def test_plot_month():
    dta = sm.datasets.elnino.load_pandas().data
    dta['YEAR'] = dta.YEAR.astype(int).apply(str)
    dta = dta.set_index('YEAR').T.unstack()
    dates = lmap(
        lambda x: pd.datetools.parse_time_string('1 ' + ' '.join(x))[0],
        dta.index.values)

    # test dates argument
    fig = month_plot(dta.values, dates=dates, ylabel='el nino')
    plt.close(fig)

    # test with a TimeSeries DatetimeIndex with no freq
    dta.index = pd.DatetimeIndex(dates)
    fig = month_plot(dta)
    plt.close(fig)

    # w freq
    dta.index = pd.DatetimeIndex(dates, freq='M')
    fig = month_plot(dta)
    plt.close(fig)

    # test with a TimeSeries PeriodIndex
    dta.index = pd.PeriodIndex(dates, freq='M')
    fig = month_plot(dta)
    plt.close(fig)
Пример #3
0
 def show_month_plot(self):
     if self.has_validation_error:
         return
     # Month_plot() requires the data to have a monthly (12 or 'M') frequency
     # Alternative: quarter_plot() for dataset with a frequency of 4 or 'Q'
     fig, ax1 = plt.subplots(1, 1, figsize=(12, 8))
     month_plot(self.series, ax=ax1)
     plt.title("Month Plot of Vaccine Demand of {} in {}".format(
         self.vaccine, self.health_facility))
     plt.grid(axis='both')
     plt.tight_layout()
     plt.show()
Пример #4
0
def test_plot_month(close_figures):
    dta = elnino.load_pandas().data
    dta["YEAR"] = dta.YEAR.astype(int).apply(str)
    dta = dta.set_index("YEAR").T.unstack()
    dates = pd.to_datetime(["-".join([x[1], x[0]]) for x in dta.index.values])

    # test dates argument
    fig = month_plot(dta.values, dates=dates, ylabel="el nino")

    # test with a TimeSeries DatetimeIndex with no freq
    dta.index = pd.DatetimeIndex(dates)
    fig = month_plot(dta)

    # w freq
    dta.index = pd.DatetimeIndex(dates, freq="MS")
    fig = month_plot(dta)

    # test with a TimeSeries PeriodIndex
    dta.index = pd.PeriodIndex(dates, freq="M")
    fig = month_plot(dta)

    # test localized xlabels
    try:
        with calendar.different_locale("DE_de"):
            fig = month_plot(dta)
            labels = [_.get_text() for _ in fig.axes[0].get_xticklabels()]
            expected = [
                "Jan",
                "Feb",
                ("Mär", "Mrz"),
                "Apr",
                "Mai",
                "Jun",
                "Jul",
                "Aug",
                "Sep",
                "Okt",
                "Nov",
                "Dez",
            ]
            for lbl, exp in zip(labels, expected):
                if isinstance(exp, tuple):
                    assert lbl in exp
                else:
                    assert lbl == exp
    except locale.Error:
        pytest.xfail(reason="Failure due to unsupported locale")
Пример #5
0
def test_plot_month(close_figures):
    dta = sm.datasets.elnino.load_pandas().data
    dta['YEAR'] = dta.YEAR.astype(int).apply(str)
    dta = dta.set_index('YEAR').T.unstack()
    dates = pd.to_datetime(['-'.join([x[1], x[0]]) for x in dta.index.values])

    # test dates argument
    fig = month_plot(dta.values, dates=dates, ylabel='el nino')

    # test with a TimeSeries DatetimeIndex with no freq
    dta.index = pd.DatetimeIndex(dates)
    fig = month_plot(dta)

    # w freq
    dta.index = pd.DatetimeIndex(dates, freq='MS')
    fig = month_plot(dta)

    # test with a TimeSeries PeriodIndex
    dta.index = pd.PeriodIndex(dates, freq='M')
    fig = month_plot(dta)
Пример #6
0
def test_plot_month(close_figures):
    dta = sm.datasets.elnino.load_pandas().data
    dta['YEAR'] = dta.YEAR.astype(int).apply(str)
    dta = dta.set_index('YEAR').T.unstack()
    dates = pd.to_datetime(['-'.join([x[1], x[0]]) for x in dta.index.values])

    # test dates argument
    fig = month_plot(dta.values, dates=dates, ylabel='el nino')

    # test with a TimeSeries DatetimeIndex with no freq
    dta.index = pd.DatetimeIndex(dates)
    fig = month_plot(dta)

    # w freq
    dta.index = pd.DatetimeIndex(dates, freq='MS')
    fig = month_plot(dta)

    # test with a TimeSeries PeriodIndex
    dta.index = pd.PeriodIndex(dates, freq='M')
    fig = month_plot(dta)
Пример #7
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)
Пример #8
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()
Пример #9
0
def main():

    # IN THE SIDEBAR
    ticker = sl.sidebar.text_input("Ticker:")
    input = sl.sidebar.date_input("Startdatum:", datetime.datetime.now())
    output = sl.sidebar.date_input("Einddatum:", datetime.datetime.now())
    try:
        df = Load_data(1000000, ticker=ticker)
        df = df.loc[str(input):str(output)]
        df1 = df.copy()

    except Exception as e:
        sl.write("Please typ in a ticker")

    sl.title("Stockdata analyzer")

    sl.write("___________________________________________")

    multi = sl.multiselect("Choose your graph",
                           ("Close", "Open", "Adj Close", "High", "Low"))
    print(multi)
    sl.write("___________________________________________")

    img = Image.open("machine-learning-840x485.png")
    sl.image(img, width=650, caption="Machine learning")

    sl.markdown("""
                    """)

    sl.markdown("""
                    """)
    sl.markdown("""
                       """)
    sl.markdown("""
                       """)

    sl.markdown("""
                           """)
    sl.markdown("""
                           """)

    sl.subheader("Graphs")
    sl.write("___________________________________________")

    sl.write("Line chart of " + ticker)
    if not sl.line_chart(df[multi]):
        sl.error("please select a ticker")

    sl.write("Bar chart of " + ticker)
    sl.bar_chart(df[multi])

    df1 = df1.resample("M").mean()

    sl.write("Month chart of " + ticker)

    plot = month_plot(df1["change"])
    sl.write(plot)

    sl.subheader("Data")
    sl.write("___________________________________________")

    sl.write(df, width=1000)


dftest = adfuller(df1['Thousands of Passengers'])

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'] )