Time Series Prediction with Machine Learning

Dec 8, 2020 | Data Science

Welcome to the world of time series prediction using machine learning! This guide will help you set up a collection of different machine learning models to predict market prices based on currency charts.

BTC_ETH chart BTC_LTC chart

Requirements

  • Required Dependency: numpy
  • Recommended Optional Dependencies: To diversify the final model ensemble, install tensorflow, xgboost.
  • Tested Python Versions: 2.7.14, 3.6.0

Fetching Data

The built-in data provider allows you to fetch data from the Poloniex exchange. Currently, it supports crypto-currency charts, and the data format includes standard OHLC trading information. You can fetch the data using the run_fetch.py script from the root directory:

sh
# Fetches the default tickers: BTC_ETH, BTC_LTC, BTC_XRP, BTC_ZEC for all time periods.
$ .run_fetch.py

By default, this will fetch data for all available time periods. You can also specify tickers and periods:

sh
# Fetches just BTC_ETH ticker data for only 3 time periods.
$ .run_fetch.py BTC_ETH --period=2h,4h,day

Note that subsequent runs will only fetch updates since the last run.

Training the Models

To train the models, execute the run_train.py script:

sh
# Trains all models until stopped.
$ .run_train.py

This will train models with default parameters including tickers, periods, and targets. You can customize it by specifying parameters:

sh
$ .run_train.py --period=4h --target=low BTC_BCH

Remember, the models will be evaluated using transformed data, predicting percent changes rather than raw values.

Machine Learning Methods

Here are the machine learning methods currently supported:

  • Ordinary Linear Model
  • Gradient Boosting (xgboost)
  • Deep Neural Network (Tensorflow)
  • Recurrent Neural Network (LSTM, GRU)
  • Convolutional Neural Network for 1-Dimensional Data

Each model accepts a window of a specific size (let’s call it k) to predict a single target value for the next time step. Consider it as a chef who needs to prepare a dish based on the last ten ingredients used. For example, if the window size is 10, the chef looks at the previous ten ingredients (x[t-10] to x[t-1]) to predict how much salt (x[t]) to add in the next dish.

Inspecting the Model

After training, the saved models contain various files for you to inspect:

  • run-params.txt: Contains information about the model, such as ticker name, time period, target column, etc.
  • model-params.txt: Holds the specific hyper-parameters.
  • stats.txt: Evaluation statistics for both training and test sets.

These files aid in understanding how well each model performed based on the test sets.

Running Predictions

To make predictions, run the run_predict.py script. This will download the current trading data and run the ensemble of several saved models:

sh
# Runs ensemble of best models for BTC_ETH ticker.
$ .run_predict.py BTC_ETH

Troubleshooting Ideas

If you encounter issues during setup or execution, consider the following troubleshooting tips:

  • Ensure all required dependencies are correctly installed.
  • If data fetching fails, check your internet connection or the availability of the Poloniex exchange.
  • For training failures, verify your Python version and library compatibility.
  • Review log files for specific error messages to identify and resolve issues.
  • For additional help, explore resources or share your problems with peers in forums.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox