From f98c7a24231b01f894b1965ca26cc689d020c29c Mon Sep 17 00:00:00 2001 From: Emre Date: Sat, 29 Oct 2022 21:11:29 +0300 Subject: [PATCH 1/2] Remove loop of normalization from metadata --- freqtrade/freqai/data_kitchen.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/freqtrade/freqai/data_kitchen.py b/freqtrade/freqai/data_kitchen.py index c0becd5ae..ee843b124 100644 --- a/freqtrade/freqai/data_kitchen.py +++ b/freqtrade/freqai/data_kitchen.py @@ -354,13 +354,18 @@ class FreqaiDataKitchen: :param df: Dataframe to be standardized """ + train_max = [] + train_min = [] for item in df.keys(): - df[item] = ( - 2 - * (df[item] - self.data[f"{item}_min"]) - / (self.data[f"{item}_max"] - self.data[f"{item}_min"]) - - 1 - ) + train_max.append(self.data[item + "_max"]) + train_min.append(self.data[item + "_min"]) + + train_max_series = pd.Series(train_max, index=df.keys()) + train_min_series = pd.Series(train_min, index=df.keys()) + + df = ( + 2 * (df - train_min_series) / (train_max_series - train_min_series) - 1 + ) return df From fc53054d431ab38d2ac42769b38b9d1de622b1e0 Mon Sep 17 00:00:00 2001 From: robcaulk Date: Sun, 30 Oct 2022 09:26:29 +0100 Subject: [PATCH 2/2] leverage list length knowledge, f-string change --- freqtrade/freqai/data_kitchen.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/freqtrade/freqai/data_kitchen.py b/freqtrade/freqai/data_kitchen.py index ee843b124..e71bddb07 100644 --- a/freqtrade/freqai/data_kitchen.py +++ b/freqtrade/freqai/data_kitchen.py @@ -354,11 +354,12 @@ class FreqaiDataKitchen: :param df: Dataframe to be standardized """ - train_max = [] - train_min = [] - for item in df.keys(): - train_max.append(self.data[item + "_max"]) - train_min.append(self.data[item + "_min"]) + train_max = [None] * len(df.keys()) + train_min = [None] * len(df.keys()) + + for i, item in enumerate(df.keys()): + train_max[i] = self.data[f"{item}_max"] + train_min[i] = self.data[f"{item}_min"] train_max_series = pd.Series(train_max, index=df.keys()) train_min_series = pd.Series(train_min, index=df.keys())