Coin Market Cap Price Forecasting
This tutorial shows how to train a forecasting model in PyTorch

Goal

We show how to create a model that learns how to forecast the next N observations of a timeseries.
In this example, we will be creating a model that predicts future cryptocurrency values.
This tutorial uses PyTorch Forecasting

Step 1: Create Your Dataset

Our dataset is quite simple: it's a CSV file with the following structure :
1
time_idx,Symbol,Date,High,Low,Open,Close,Volume,Marketcap
2
1,ADA,2017-10-02 23:59:59,0.0300877001136541,0.0199692994356155,0.0246070008724927,0.0259317997843027,57641300.0,628899051.78
3
2,ADA,2017-10-03 23:59:59,0.0274251997470855,0.0206898991018533,0.025756599381566,0.0208158008754253,16997800.0,539692714.905
Copied!
We will training a series of models on Grid. Now, in order to make the process of updating the dataset easier we will be creating a Grid Datastore. Datstores are collections of files that are versioned and can be mounted anywhere in the experiment context.
We'll be creating a new Datastore using the Grid CLI with the following command:
1
$ grid datastores create --name crypto_prices --source data/
2
upload ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0%
3
✔ Finished uploading datastore.
Copied!
Then check that your datsatore is ready to use by calling grid datastores list:
1
$ grid datstores list
2
┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
3
┃ Credential Id ┃ Name ┃ Version ┃ Size ┃ Created ┃ Status ┃
4
┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
5
│ cc-grv4f │ crypto_prices │ 1 │ 12.6 MB │ 2021-05-20 01:17 │ Succeeded │
6
└───────────────┴─────────────────────┴─────────┴──────────┴──────────────────┴───────────┘
Copied!
Whenever your datastore has Status of Succeeded you are ready to go on training.

Step 2: Train Your Model on Grid AI

You are now ready to train your model on Grid.
We'll be using the CLI but you can do the same thing by using the web UI. We have placed a configuration file locally (.grid/config.yml) that you can use as reference instead of passing all the parameters to the CLI manually.
This is the script we will be using: https://github.com/gridai/gridai-timeseries-forecasting-demo
1
$ grid run --config .grid/config.yml \
2
train.py \
3
--max_epochs 100 \
4
--data_path /dataset/cryptocurrency_prices.csv \
5
--learning_rate "uniform(0,0.03,5)" \
6
--hidden_size "[16,32,64]"
7
8
No --name passed, naming your run glossy-manatee-255
9
Using default cloud credentials cc-bwhth to run on AWS.
10
11
Run submitted!
12
`grid status` to list all runs
13
`grid status glossy-manatee-255` to see all experiments for this run
14
15
----------------------
16
Submission summary
17
----------------------
18
script: train.py
19
instance_type: g4dn.xlarge
20
distributed: False
21
use_spot: True
22
cloud_provider: aws
23
cloud_credentials: cc-bwhth
24
grid_name: glossy-manatee-255
25
datastore_name: crypto_prices
26
datastore_version: 1
27
datastore_mount_dir: /dataset
Copied!

Bonus: Run a Hyperparameter Sweep

Grid AI makes it trivial to run a hyperparameter sweep without having to change anything in your scripts. Let's experiment with a number of different learning rates for our model:
1
$ grid run --config .grid/config.yml \
2
train.py --max_epochs 100 \
3
--data_path /dataset/cryptocurrency_prices.csv \
4
--learning_rate "uniform(0,0.03,5)" \
5
--hidden_size "[16,32,64]"
Copied!
That will generate 15 experiments with different learning rate combinations.

Attribution

This project relies heavily on the PyTorch Forecasting package. The implementation adapts from their documentation and tutorials.
The dataset used in this demo comes from CoinMarketCap, a cryptocurrency price-tracking service. We have downloaded a processed version of the data available on this Kaggle page.
Last modified 3mo ago