From 665eed39060cbc20277ba27cc2959780e6c9b180 Mon Sep 17 00:00:00 2001 From: robcaulk Date: Tue, 6 Dec 2022 23:26:07 +0100 Subject: [PATCH] add documentation for CNN, allow it to interact with model_training_parameters --- docs/freqai-configuration.md | 20 +++++++++++++++++++ .../prediction_models/CNNPredictionModel.py | 12 ++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/docs/freqai-configuration.md b/docs/freqai-configuration.md index 5c3bbf90c..b7ee1a4c5 100644 --- a/docs/freqai-configuration.md +++ b/docs/freqai-configuration.md @@ -242,3 +242,23 @@ If you want to predict multiple targets you must specify all labels in the same df['&s-up_or_down'] = np.where( df["close"].shift(-100) > df["close"], 'up', 'down') df['&s-up_or_down'] = np.where( df["close"].shift(-100) == df["close"], 'same', df['&s-up_or_down']) ``` + +### Convolutional Neural Network model + +The `CNNPredictionModel` is a non-linear regression based on `Tensorflow` which follows very similar configuration to the other regressors. Feature engineering and label creation remains the same as highlighted [here](#building-a-freqai-strategy) and [here](#setting-model-targets). Control of the model is focused in the `model_training_parameters` configuration dictionary, which accepts any hyperparameter available to the CNN `fit()` function of Tensorflow [more here](https://www.tensorflow.org/api_docs/python/tf/keras/Model#fit). For example, this is where the `epochs` and `batch_size` are controlled: + +```json + "model_training_parameters" : { + "batch_size": 64, + "epochs": 10, + "verbose": "auto", + "shuffle": false + "workers": 1, + "use_multiprocessing": False + } +``` + +Running the `CNNPredictionModel` is the same as other regressors: `--freqaimodel CNNPredictionModel`. + + +``` \ No newline at end of file diff --git a/freqtrade/freqai/prediction_models/CNNPredictionModel.py b/freqtrade/freqai/prediction_models/CNNPredictionModel.py index ed67088e5..3b4de4ca3 100644 --- a/freqtrade/freqai/prediction_models/CNNPredictionModel.py +++ b/freqtrade/freqai/prediction_models/CNNPredictionModel.py @@ -17,8 +17,6 @@ logger = logging.getLogger(__name__) # tf.config.run_functions_eagerly(True) # tf.data.experimental.enable_debug_mode() -MAX_EPOCHS = 10 - class CNNPredictionModel(BaseTensorFlowModel): """ @@ -46,7 +44,12 @@ class CNNPredictionModel(BaseTensorFlowModel): ) n_features = len(data_dictionary["train_features"].columns) - BATCH_SIZE = self.freqai_info.get("batch_size", 64) + BATCH_SIZE = self.model_training_parameters.get("batch_size", 64) + + # we need to remove batch_size from the model_training_params because + # we dont want fit() to get the incorrect assignment (we use the WindowGenerator) + # to handle our batches. + self.model_training_parameters.pop('batch_size') input_dims = [BATCH_SIZE, self.CONV_WIDTH, n_features] w1 = WindowGenerator( @@ -84,8 +87,7 @@ class CNNPredictionModel(BaseTensorFlowModel): model.fit( w1.train, - epochs=MAX_EPOCHS, - shuffle=False, + **self.model_training_parameters, validation_data=val_data, callbacks=[early_stopping], verbose=1,