Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
khuangaf committed Dec 31, 2017
1 parent 1b18a24 commit 91194db
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 73 deletions.
50 changes: 25 additions & 25 deletions .ipynb_checkpoints/Plot_GRU-checkpoint.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions GRU.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
labels = hf['outputs'].value


output_file_name='bitcoin2015to2017_close_CuGRU_1_tanh_relu_'
output_file_name='bitcoin2015to2017_close_GRU_1_tanh_relu_'

step_size = datas.shape[1]
units= 50
Expand All @@ -43,7 +43,7 @@

#build model
model = Sequential()
model.add(CuDNNGRU(units=units, input_shape=(step_size,nb_features),return_sequences=False))
model.add(GRU(units=units, input_shape=(step_size,nb_features),return_sequences=False))
model.add(Activation('tanh'))
model.add(Dropout(0.2))
model.add(Dense(output_size))
Expand Down
70 changes: 28 additions & 42 deletions Plot_GRU.ipynb

Large diffs are not rendered by default.

37 changes: 33 additions & 4 deletions Plot_LSTM.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
"cells": [
{
"cell_type": "code",
"execution_count": 247,
"execution_count": 1,
"metadata": {
"collapsed": true,
"scrolled": true
},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
]
}
],
"source": [
"from keras import applications\n",
"from keras.models import Sequential\n",
Expand All @@ -33,6 +40,26 @@
"import h5py"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"u'0.20.3'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.__version__"
]
},
{
"cell_type": "code",
"execution_count": 248,
Expand Down Expand Up @@ -160,7 +187,9 @@
{
"cell_type": "code",
"execution_count": 255,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"model = Sequential()\n",
Expand Down
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Deep Learning for Cryptocurrency Price Prediction
<div float="left">
<img src="https://www.tensorflow.org/images/tf_logo_transp.png" height="120" >
<img src="https://s3.amazonaws.com/keras.io/img/keras-logo-2018-large-1200.png" height="120">
</div>
<div float="right">

</div>

##

### Introduction
This repo makes use of the state-of-art Deep Learning algorithm to predict the price of Bitcoin, which has the potential to generalize to other cryptocurrency. It leverages models such as CNN and RNN implemented by [Keras](https://github.com/keras-team/keras) running on top of [Tensorflow](https://github.com/tensorflow/tensorflow).

### Getting Started
To run this repo, be sure to install the following environment and library:

1. Python 2.7
2. Tensorflow=1.2.0
3. Keras=2.1.1
4. Pandas=0.20.3
5. Numpy=1.13.3
6. h5py=2.7.0
7. sklearn=0.19.1

### File Illustration
#### There are currently three different models:
1. LSTM.py
2. GRU.py
3. CNN.py (1 dimensional CNN)

#### The validation result is plotted in:
1. Plot_LSTM.ipynb
2. Plot_GRU.ipynb
3. Plot_CNN.ipynb

#### Data is collected from [poloniex](https://poloniex.com) and parse to h5py file:
1. DataCollection.ipynb
2. PastSampler.ipynb

### Input & Output & Loss
The input consists of a list of past Bitcoin data with step size of 256.
The output is the predicted value of the future data with step size of 16. Note that since the data is ticked every five minutes, the input data spans over the past 1280 minutes, while the output cover the future 80 minutes. The datas are scaled with MinMaxScaler provided by sklearn over the entire dataset. The loss is defined as Mean Square Error (MSE).

### Result
|Model | #Layers | Activation | Validation Loss |Validation Loss (Scale Inverted) |
|----------| ------------- |------|-------| -----|
| CNN | 2 | ReLU | 0.00029 | 114308 |
| CNN | 2 | Leaky ReLU | 0.00029 | 115525 |
| CNN | 3 | ReLU | 0.00029 | 201718 |
| CNN | 3 | Leaky ReLU | 0.00028 | 108700 |
| CNN | 4 | ReLU | 0.00030 | 117947 |
| CNN | 4 | Leaky ReLU | 0.03217 | 12356304 |
| LSTM | 1 | tanh + ReLU | 0.00007 | 26649 |
| LSTM | 1 | tanh + Leaky ReLU | 0.00004 | 15364 |
| GRU | 1 | tanh + ReLU | 0.00004 | 17667 |
| GRU | 1 | tanh + Leaky ReLU | 0.00004 | 15474 |


Each row of the above table is the model that derives the best validation loss from the total 100 training epochs. From the above result, we can observe that LeakyReLU always seems to yield better loss compared to regular ReLU. However, 4-layered CNN with Leaky ReLU as activation function creates a large validation loss, this can due to wrong deployment of model which might require re-validation. Although CNN model can be trained very fast (2 seconds/ epoch with GPU), with slightly worse performance than LSTM and GRU. The best model seems to be LSTM with tanh and Leaky ReLU as activation function, though 3-layered CNN seems to be better in capturing local temporal dependency of data.
<div align="center">
<img src="result/bitcoin2015to2017_close_LSTM_1_tanh_leaky_result.png" width="80%" />
</div>

_LSTM with tanh and Leaky ReLu as activation function._

<div align="center">
<img src="result/bitcoin2015to2017_close_CNN_3_leaky_result.png" width="80%" />
</div>

_3-layered CNN with Leaky ReLu as activation function._

### Future Work
Since there is still a gap between training and validation loss, (3.87E-06 vs 2.02E-05), I will be focusing on regularizing the network to decrease the variance.

Binary file modified result/bitcoin2015to2017_close_GRU_1_tanh_relu_result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 91194db

Please sign in to comment.