diff --git a/docs/freqai-parameter-table.md b/docs/freqai-parameter-table.md
index c5f310172..23d2be8ef 100644
--- a/docs/freqai-parameter-table.md
+++ b/docs/freqai-parameter-table.md
@@ -45,6 +45,7 @@ Mandatory parameters are marked as **Required** and have to be set in one of the
| `noise_standard_deviation` | If set, FreqAI adds noise to the training features with the aim of preventing overfitting. FreqAI generates random deviates from a gaussian distribution with a standard deviation of `noise_standard_deviation` and adds them to all data points. `noise_standard_deviation` should be kept relative to the normalized space, i.e., between -1 and 1. In other words, since data in FreqAI is always normalized to be between -1 and 1, `noise_standard_deviation: 0.05` would result in 32% of the data being randomly increased/decreased by more than 2.5% (i.e., the percent of data falling within the first standard deviation).
**Datatype:** Integer.
Default: `0`.
| `outlier_protection_percentage` | Enable to prevent outlier detection methods from discarding too much data. If more than `outlier_protection_percentage` % of points are detected as outliers by the SVM or DBSCAN, FreqAI will log a warning message and ignore outlier detection, i.e., the original dataset will be kept intact. If the outlier protection is triggered, no predictions will be made based on the training dataset.
**Datatype:** Float.
Default: `30`.
| `reverse_train_test_order` | Split the feature dataset (see below) and use the latest data split for training and test on historical split of the data. This allows the model to be trained up to the most recent data point, while avoiding overfitting. However, you should be careful to understand the unorthodox nature of this parameter before employing it.
**Datatype:** Boolean.
Default: `False` (no reversal).
+| `shuffle_after_split` | Split the data into train and test sets, and then shuffle both sets individually.
**Datatype:** Boolean.
Default: `False`.
### Data split parameters
diff --git a/freqtrade/constants.py b/freqtrade/constants.py
index b2e707d1a..a724664a4 100644
--- a/freqtrade/constants.py
+++ b/freqtrade/constants.py
@@ -568,7 +568,8 @@ CONF_SCHEMA = {
"shuffle": {"type": "boolean", "default": False},
"nu": {"type": "number", "default": 0.1}
},
- }
+ },
+ "shuffle_after_split": {"type": "boolean", "default": False}
},
"required": ["include_timeframes", "include_corr_pairlist", ]
},
diff --git a/freqtrade/freqai/data_kitchen.py b/freqtrade/freqai/data_kitchen.py
index 70e5549f9..30d2509b5 100644
--- a/freqtrade/freqai/data_kitchen.py
+++ b/freqtrade/freqai/data_kitchen.py
@@ -1,6 +1,7 @@
import copy
import inspect
import logging
+import random
import shutil
from datetime import datetime, timezone
from math import cos, sin
@@ -170,6 +171,19 @@ class FreqaiDataKitchen:
train_labels = labels
train_weights = weights
+ if feat_dict["shuffle_after_split"]:
+ rint1 = random.randint(0, 100)
+ rint2 = random.randint(0, 100)
+ train_features = train_features.sample(
+ frac=1, random_state=rint1).reset_index(drop=True)
+ train_labels = train_labels.sample(frac=1, random_state=rint1).reset_index(drop=True)
+ train_weights = pd.DataFrame(train_weights).sample(
+ frac=1, random_state=rint1).reset_index(drop=True).to_numpy()[:, 0]
+ test_features = test_features.sample(frac=1, random_state=rint2).reset_index(drop=True)
+ test_labels = test_labels.sample(frac=1, random_state=rint2).reset_index(drop=True)
+ test_weights = pd.DataFrame(test_weights).sample(
+ frac=1, random_state=rint2).reset_index(drop=True).to_numpy()[:, 0]
+
# Simplest way to reverse the order of training and test data:
if self.freqai_config['feature_parameters'].get('reverse_train_test_order', False):
return self.build_data_dictionary(
diff --git a/tests/freqai/conftest.py b/tests/freqai/conftest.py
index bee7df27e..5e8945239 100644
--- a/tests/freqai/conftest.py
+++ b/tests/freqai/conftest.py
@@ -46,6 +46,7 @@ def freqai_conf(default_conf, tmpdir):
"use_SVM_to_remove_outliers": True,
"stratify_training_data": 0,
"indicator_periods_candles": [10],
+ "shuffle_after_split": False
},
"data_split_parameters": {"test_size": 0.33, "shuffle": False},
"model_training_parameters": {"n_estimators": 100},
diff --git a/tests/freqai/test_freqai_interface.py b/tests/freqai/test_freqai_interface.py
index 79c04e6b3..55f9e8fde 100644
--- a/tests/freqai/test_freqai_interface.py
+++ b/tests/freqai/test_freqai_interface.py
@@ -27,19 +27,20 @@ def is_mac() -> bool:
return "Darwin" in machine
-@pytest.mark.parametrize('model, pca, dbscan, float32, can_short', [
- ('LightGBMRegressor', True, False, True, True),
- ('XGBoostRegressor', False, True, False, True),
- ('XGBoostRFRegressor', False, False, False, True),
- ('CatboostRegressor', False, False, False, True),
- ('ReinforcementLearner', False, True, False, True),
- ('ReinforcementLearner_multiproc', False, False, False, True),
- ('ReinforcementLearner_test_3ac', False, False, False, False),
- ('ReinforcementLearner_test_3ac', False, False, False, True),
- ('ReinforcementLearner_test_4ac', False, False, False, True)
+@pytest.mark.parametrize('model, pca, dbscan, float32, can_short, shuffle', [
+ ('LightGBMRegressor', True, False, True, True, False),
+ ('XGBoostRegressor', False, True, False, True, False),
+ ('XGBoostRFRegressor', False, False, False, True, False),
+ ('CatboostRegressor', False, False, False, True, True),
+ ('ReinforcementLearner', False, True, False, True, False),
+ ('ReinforcementLearner_multiproc', False, False, False, True, False),
+ ('ReinforcementLearner_test_3ac', False, False, False, False, False),
+ ('ReinforcementLearner_test_3ac', False, False, False, True, False),
+ ('ReinforcementLearner_test_4ac', False, False, False, True, False)
])
def test_extract_data_and_train_model_Standard(mocker, freqai_conf, model, pca,
- dbscan, float32, can_short):
+ dbscan, float32, can_short, shuffle):
+
if is_arm() and model == 'CatboostRegressor':
pytest.skip("CatBoost is not supported on ARM")
@@ -53,6 +54,7 @@ def test_extract_data_and_train_model_Standard(mocker, freqai_conf, model, pca,
freqai_conf['freqai']['feature_parameters'].update({"principal_component_analysis": pca})
freqai_conf['freqai']['feature_parameters'].update({"use_DBSCAN_to_remove_outliers": dbscan})
freqai_conf.update({"reduce_df_footprint": float32})
+ freqai_conf['freqai']['feature_parameters'].update({"shuffle_after_split": shuffle})
if 'ReinforcementLearner' in model:
model_save_ext = 'zip'