<jupyter_start><jupyter_text>Bitcoin Forecast - ARMA & ARIMA<jupyter_code>import pandas as pd
import numpy as np
from pandas.tools.plotting import autocorrelation_plot
from statsmodels.graphics.tsaplots import plot_acf
import statsmodels.api as sm
from sklearn.metrics import mean_absolute_error

%matplotlib inline

import warnings; warnings.simplefilter('ignore')
df_bitcoin = pd.read_csv("../../assets/dataset/bitcoin.csv")
df_bitcoin['date_format'] = pd.to_datetime(df_bitcoin['date_format'])
df_bitcoin.set_index('date_format', inplace=True)
df_bitcoin.head()
df_bitcoin['Close'].plot()
max(df_bitcoin.index)
df_bitcoin_train = df_bitcoin.loc[:"2018-02-8",["Close"]]
df_bitcoin_test = df_bitcoin.loc["2018-02-9":,["Close"]]
df_bitcoin_train['Close'].plot()
df_bitcoin_train.tail()
df_bitcoin_test
plot_acf(df_bitcoin_train, lags=30)
model = sm.tsa.ARIMA(df_bitcoin_train, (1, 0, 0)).fit()

predictions = model.predict(
    '2018-02-09',
    '2018-02-11',
    dynamic=True, 
)

predictions
print("Mean absolute error: ", mean_absolute_error(df_bitcoin_test, predictions))
model.summary()
model = sm.tsa.ARIMA(df_bitcoin_train, (1, 0, 1)).fit()

predictions = model.predict(
    '2018-02-09',
    '2018-02-11',
    dynamic=True, 
)

predictions
print("Mean absolute error: ", mean_absolute_error(df_bitcoin_test, predictions))
model.summary()
model = sm.tsa.ARIMA(df_bitcoin_train, (1, 1, 1)).fit()

predictions = model.predict(
    '2018-02-09',
    '2018-02-11',
    dynamic=False, 
    typ='levels'
)

predictions
print("Mean absolute error: ", mean_absolute_error(df_bitcoin_test, predictions))
model.summary()<jupyter_output>Mean absolute error:  281.01129051707204
{'fraction_non_alphanumeric': 0.1434548714883443, 'fraction_numerical': 0.05379557680812911, 'mean_word_length': 6.153846153846154, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '395789', 'license': 'MIT', 'n_tokens_mistral': 685, 'n_tokens_neox': 619, 'n_words': 105, 'path': 'Intro to Data Science with Python Beginners Bootcamp Andrew August/10_time_series/Bitcoin Forecasting.ipynb', 'repo_name': 'alistairwalsh/p4ds', 'size': '1673'}