]> AND Private Git Repository - predictops.git/blobdiff - predictops/learn/preprocessing.py
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Reducing the computation time and adding holidays features
[predictops.git] / predictops / learn / preprocessing.py
index 106a6267c3aa804aca024c471e5c7b6e29805799..885aad3393979b897e3e0d8c40f3378dbba08e5a 100644 (file)
@@ -48,28 +48,22 @@ class Preprocessing:
         self._features = set(chain.from_iterable([tuple(u.keys())
                                                       for u in [*dict_features.values()]]))
 
-        feature_files = Path.cwd() / 'config' / 'features'
-        self._features = {feat : {'numerical': False} for feat in self._features}
-        for feature_file in listdir(feature_files):
-            if feature_file.endswith('csv'):
-                with open(feature_files / feature_file , "r") as f:
-                    reader = DictReader(f, delimiter=',')
-                    typed_names = {row['name']: row['type'] for row in reader}
-                for feature in self._features:
-                    if feature.split('_')[0] in typed_names:
-                        self._features[feature]['type'] = int(typed_names[feature.split('_')[0]])
-            elif feature_file.endswith('cfg'):
+        #feature_files = Path.cwd() / 'config' / 'features'
+        self._features = {feat : {'numerical': False, 'categorical': False}
+                          for feat in self._features}
+
+        for feature in self._config['FEATURES']:
+            if self._config['FEATURES'][feature]:
+                feature_file = self._config['FEATURE_CONFIG'][feature]
                 config = ConfigParser()
-                config.read(feature_files / feature_file)
+                config.read(feature_file)
                 for section in config:
                     if config.has_option(section, 'numerical'):
                         self._features[section]['numerical'] = config[section].getboolean('numerical')
+                        self._features[section]['categorical'] = config[section].getboolean('categorical')
 
-        self._numerical_columns = [k for k in self._features if self._features[k]['type'] == 1
-                   or (self._features[k]['type'] == 3 and self._features[k]['numerical'])]
-
-        self._categorical_columns = [k for k in self._features if self._features[k]['type'] == 2
-                   or (self._features[k]['type'] == 3 and not self._features[k]['numerical'])]
+        self._numerical_columns = [k for k in self._features if self._features[k]['numerical']]
+        self._categorical_columns = [k for k in self._features if self._features[k]['categorical']]
 
 
 
@@ -172,12 +166,11 @@ class Preprocessing:
         # Dropping rows that are not related to our datetime window (start/
         # step / end)
         logger.info("Dropping rows that are not related to our datetime window")
-        self._dataframe['datetime'] =\
-            self._dataframe.apply(lambda x: datetime(int(x.year), int(x.month), int(x.dayInMonth), int(x.hour)), axis=1)
+        dates = tuple((x.year, x.month, x.day, x.hour) for x in self._datetimes)
         self._dataframe['row_ok'] =\
-            self._dataframe.apply(lambda x:x.datetime in self._datetimes, axis=1)
+            self._dataframe.apply(lambda x: (int(x.year), int(x.month), int(x.dayInMonth), int(x.hour)) in dates, axis=1)
         self._dataframe = self._dataframe[self._dataframe['row_ok']]
-        self._dataframe = self._dataframe.drop(['datetime', 'row_ok'], axis=1)
+        self._dataframe = self._dataframe.drop(['row_ok'], axis=1)
         logger.info("Rows dropped")