Machine Learning

Key Concepts

Introduction

Machine learning is a field of study that combines statistics and computer science to build intelligent systems that predict outcomes. You can use machine learning techniques in your trading strategies.

Supported Libraries

LEAN supports several machine learning libraries. You can import these packages and use them in your algorithms.

NameVersionLanguageImport StatementExample
Tensor Flow1.13.1Pythonimport tensorflow
SciKit Learn0.21.3Pythonimport sklearn
Py Torch1.1.0Pythonimport torch
Keras2.2.4Pythonimport keras
Theano1.0.4Pythonimport theano
hmmlearn0.2.2Pythonimport hmmlearn
tsfresh0.12.0Pythonimport tsfresh
fastai1.0.54Pythonimport fastai
Deap1.0.54Pythonimport deap
mlfinlab0.9.3Pythonimport mlfinlab
Accord3.60CSharpusing Accord.MachineLearning;
AForge.Neuro2.2.5CSharpusing AForge.Neuro;

For a comprehensive list of all the supported libraries, see Libraries.

Add New Libraries

To request a new library, contact us. We will add the library to the queue for review and deployment. Since the libraries run on our servers, we need to ensure they are secure and won't cause harm. The process of adding new libraries takes 2-4 weeks to complete. View the list of libraries currently under review on the Issues list of the Lean GitHub repository.

Save Models

After you train a model, you can save it into the Object Store. In QC Cloud, we back up your Object Store data on QuantConnect servers. In local algorithms, your local machine saves the Object Store data. If you save models in live algorithms, save them at the end of the training method so you can access the trained model again if your algorithm stops executing. If you save models in backtests, save them during the OnEndOfAlgorithm event handler so that saving multiple times doesn't slow down your backtest.

To view examples of storing library-specific models, see Popular Libraries.

Load Models

You can load machine learning models from the Object Store or a custom data file like pickle. If you load models from the Object Store, before you load the model into your algorithm, in the Initialize method, check if the Object Store already contains the model. To avoid look-ahead bias in backtests, don't train your model on the same data you use to test the model.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: