Commit 9f033f66 authored by Matt Harrison's avatar Matt Harrison
Browse files

bump libs

parent 23d5a582
Loading
Loading
Loading
Loading
+121 −1761

File changed.

Preview size limit exceeded, changes collapsed.

+11 −11
Changes for requirements.txt: 11 added lines, 11 removed lines.
Original line number Diff line number Diff line
shap==0.35.0
matplotlib==3.2.1
notebook==6.0.3
numpy==1.18.4
pandas==1.0.3
matplotlib==3.3.3
notebook==6.1.5
numpy==1.19.4
pandas==1.1.4
scikit-learn==0.23.2
scipy==1.5.4
seaborn==0.11.0
shap==0.37.0
xgbfir==0.3.1
xgboost==1.0.2
xgboost==1.2.1
xlrd==1.2.0
XlsxWriter==1.2.8
yellowbrick==1.1
scikit-learn==0.22.2.post1
scipy==1.4.1
seaborn==0.10.1
XlsxWriter==1.3.7
yellowbrick==1.2
+321 −869

File changed.

Preview size limit exceeded, changes collapsed.

+39 −27
Changes for solutions/Supervised ML.py: 39 added lines, 27 removed lines.
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.4.2
#       jupytext_version: 1.7.1
#   kernelspec:
#     display_name: Python 3
#     language: python
@@ -37,22 +37,25 @@ from yellowbrick import regressor

 %%time
# Resampling data from minute interval to day
bit_df = pd.read_csv('../data/coinbaseUSD_1-min_data_2014-12-01_to_2018-01-08.csv')
bit_df = (pd.read_csv('../data/coinbaseUSD_1-min_data_2014-12-01_to_2018-01-08.csv')
    # Convert unix time to datetime
bit_df['date'] = pd.to_datetime(bit_df.Timestamp, unit='s')
    .assign(date=lambda df_:pd.to_datetime(df_.Timestamp, unit='s'))
    # Reset index
bit_df = bit_df.set_index('date')
    .set_index('date')
    # Rename columns so easier to code
bit_df = bit_df.rename(columns={'Open':'open', 'High': 'hi', 'Low': 'lo', 
    .rename(columns={'Open':'open', 'High': 'hi', 'Low': 'lo', 
                     'Close': 'close', 'Volume_(BTC)': 'vol_btc',
                     'Volume_(Currency)': 'vol_cur', 
                     'Weighted_Price': 'wp', 'Timestamp': 'ts'})
    # Resample and only use recent samples that aren't missing
bit_df = bit_df.resample('d').agg({'open': 'first', 'hi': 'max', 
    .resample('d')
    .agg({'open': 'first', 'hi': 'max', 
        'lo': 'min', 'close': 'last', 'vol_btc': 'sum',
    'vol_cur': 'sum', 'wp': 'mean', 'ts': 'min'}).iloc[-1000:]
        'vol_cur': 'sum', 'wp': 'mean', 'ts': 'min'})
    # drop last row as it is not complete                        
bit_df = bit_df.iloc[:-1]
    .iloc[-1000:-1]
)           


bit_df

@@ -99,10 +102,9 @@ ax.plot(X, X*lr_model.coef_ + lr_model.intercept_+ 100, linestyle='--', color='g
# regression tries to minimize the square of the distance.
metrics.mean_squared_error(y, pred) 

# Vertical distance between line and point is the error. *Ordinary Least Squares* 
# regression tries to minimize the square of the distance.
metrics.mean_squared_error(y, pred) 
metrics.mean_absolute_error(y, pred) 

lr_model.score(X, y)


# ### Lab Data
@@ -258,25 +260,28 @@ from sklearn import ensemble, model_selection, preprocessing, tree
from yellowbrick import classifier


# %%time
 %%time
# Resampling data from minute interval to day
bit_df = pd.read_csv('../data/coinbaseUSD_1-min_data_2014-12-01_to_2018-01-08.csv')
bit_df = (pd.read_csv('../data/coinbaseUSD_1-min_data_2014-12-01_to_2018-01-08.csv')
    # Convert unix time to datetime
bit_df['date'] = pd.to_datetime(bit_df.Timestamp, unit='s')
    .assign(date=lambda df_:pd.to_datetime(df_.Timestamp, unit='s'))
    # Reset index
bit_df = bit_df.set_index('date')
    .set_index('date')
    # Rename columns so easier to code
bit_df = bit_df.rename(columns={'Open':'open', 'High': 'hi', 'Low': 'lo', 
    .rename(columns={'Open':'open', 'High': 'hi', 'Low': 'lo', 
                     'Close': 'close', 'Volume_(BTC)': 'vol_btc',
                     'Volume_(Currency)': 'vol_cur', 
                     'Weighted_Price': 'wp', 'Timestamp': 'ts'})
    # Resample and only use recent samples that aren't missing
bit_df = bit_df.resample('d').agg({'open': 'first', 'hi': 'max', 
    .resample('d')
    .agg({'open': 'first', 'hi': 'max', 
        'lo': 'min', 'close': 'last', 'vol_btc': 'sum',
    'vol_cur': 'sum', 'wp': 'mean', 'ts': 'min'}).iloc[-1000:]
bit_df['buy'] = (bit_df.close.shift(-1) > bit_df.close).astype(int)
        'vol_cur': 'sum', 'wp': 'mean', 'ts': 'min'})
    # drop last row as it is not complete  
bit_df = bit_df.iloc[:-1]
    .assign(buy=lambda df_:(df_.close.shift(-1) > df_.close).astype(int))
    .iloc[-1000:-1]
)           


bit_df

@@ -292,6 +297,9 @@ bit_df.describe()
# * To predict values of y (y hat), call `.predict(X)`
# * To get the accuracy call `.score(X, y)`

# Calculating is NP hard problem (hence randomness)
# Uses GINI Impurity by default
# https://en.wikipedia.org/wiki/Decision_tree_learning#Gini_impurity
ignore = {'buy'}
cols = [c for c in bit_df.columns if c not in ignore]
X = bit_df[cols]
@@ -317,9 +325,10 @@ tree.export_graphviz(dt_model, out_file='/tmp/tree1.dot',
                    filled=True
                    )

%%bash
# This doesn't run on Windows. Also requires that you have graphviz installed (not a Python module)
dot -Tpng -otree1.png /tmp/tree1.dot
# + language="bash"
# # This doesn't run on Windows. Also requires that you have graphviz installed (not a Python module)
# dot -Tpng -otree1.png /tmp/tree1.dot
# -

# <img src="tree1.png">

@@ -401,6 +410,13 @@ classifier.confusion_matrix(dt_model, X_train, y_train, X_test, y_test,
classifier.roc_auc(dt_model, X_train, y_train, X_test, y_test,
                   classes=['sell', 'buy'], micro=False, macro=False)

# Using more data to create a more normal plot
# aspect fixing
fig, ax = plt.subplots(figsize=(4,4))
classifier.roc_auc(dt_model, X_train, y_train, X, y,
                   classes=['sell', 'buy'], micro=False, macro=False,
                  ax=ax)

classifier.precision_recall_curve(dt_model, X_train, y_train, X_test, y_test,
                   classes=['sell', 'buy'], micro=False, macro=False)

@@ -430,7 +446,3 @@ classifier.roc_auc(mush_dt, mush_X_train, mush_y_train, mush_X_test, mush_y_test